<?php
defined('BASEPATH') or exit('No direct script access allowed');


class Customer extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();

       if ($this->userinfo['group'] != 1 && $this->userinfo['group'] != 4 && $this->userinfo['group'] != 5 && $this->userinfo['group'] != 6) {
           $header = getallheaders();
           if (!isset($header['Isajax'])) {
               $this->groupjunp($this->userinfo['group']);
           }else{
               $arr = array();
               $arr['code'] = 1;
               $arr['msg'] = '权限不足';
               $this->sendjsonmsg($arr);
           }
        }
    }

    //主页
    public function index()
    {
        $this->address = '后台管理首页';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->model('Jd_task_jd_list_model');
        //$row['pdd'] = $this->getttaolinfo(2);
        $this->load->view('Customer/index');
    }


    public function getttaolinfo($type = 0)
    {
        $month = $this->Jd_task_jd_list_model->getmonthdataall($type);
        $day = $this->Jd_task_jd_list_model->gettodayall($type);
        $week = $this->Jd_task_jd_list_model->getweekdata($type);
        //var_dump($week); exit;
        $days = explode("-", date('Y-m-d'));
        $days = intval($days[2]);
        $row['monthend'] = 0;
        $row['monthlost'] = 0;
        $row['daylost'] = 0;
        $row['dayend'] = 0;

        $row['weekall'] = 0;
        foreach ($month as $id => $v) {
            if ($v['status'] == 1 || $v['status'] == 0) {
                $row['monthlost'] += $v['all'];
            } else {
                $row['monthend'] += $v['all'];
            }
        }
        foreach ($day as $id => $v) {
            if ($v['status'] == 1 || $v['status'] == 0) {
                $row['daylost'] += $v['all'];
            } else {
                $row['dayend'] += $v['all'];
            }
        }


        $row['monthavg'] = round($row['monthend'] / $days, 2);
        return $row;
    }


    public function getindexinfo()
    {
        $this->load->model('Jd_task_jd_list_model');
        $this->load->model('Jd_day_count_model');
        $date1 = $this->input->post('date1') ? $this->input->post('date1') : date('2019-01-10');;
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : date('Y-m-d');
        $row = array();
        $list['day'] = date('Y-m-d');
        $list['yestody'] = date('Y-m-d', time() - 24 * 3600);
        $list['list'] = $date1;
        $webid = $this->input->post('webid');

        if ($webid != "") {
            $param['webid'] = $webid;
        } else {
            $param = array();
        }
        $this->load->model('Jd_users_model');
        $this->load->model('Jd_pay_log_model');
        foreach ($list as $id => $v) {
            $start = $v;
            $end = date('Y-m-d 23:59:59', strtotime($v));
            if ($id == 'list') {
                $end = $date2;
            }
            $nowrow = $this->Jd_task_jd_list_model->getweekdata($start, $end, $param);
            $sendnum = $this->Jd_task_jd_list_model->getSendNumber($start, $end, $param);
            $row[$id]['sendnum'] = intval($sendnum['sendnum']);
            $row[$id]['not'] = 0;
            $row[$id]['finlish'] = 0;
            $row[$id]['profit'] = 0;

            //var_dump($nowrow); exit;
            foreach ($nowrow as $id2 => $v2) {
                if (isset($v2['all'])) {
                    $v2['all'] = intval($v2['all']);
                } else {
                    $v2['all'] = 0;
                }
                if ($v2['status'] == 0) {
                    $row[$id]['not'] += $v2['all'];
                }
                if ($v2['status'] == 1) {
                    $row[$id]['not'] += $v2['all'];
                }
                if ($v2['status'] == 2) {
                    $row[$id]['finlish'] = $v2['all'];
                    $row[$id]['profit'] = $v2['all'] ? round(($v2['gold'] - $v2['cost']) * 0.9, 2) : 0;
                    $row[$id]['profit'] = round($row[$id]['profit'] - $v2['cost3'], 2);
                    $row[$id]['profit'] = round($row[$id]['profit'] - $v2['cost4'], 2);
                    $row[$id]['profit'] = round($row[$id]['profit'] - $v2['cost5'], 2);

                    if ($webid == 1) {
                        //$row[$id]['profit'] = $v2['all'] ? round(($v2['gold'] * 0.9 - $v2['cost2'] - $v2['cost3']), 2) : 0;
                    }
                }
            }
            $reg = $this->Jd_users_model->getreg($start, $end, $webid);
            $payday = $this->Jd_pay_log_model->getallmoney(1, "", $webid, $start, $end);
            $row[$id]['regnum'] = 0;
            $row[$id]['pay'] = 0;
            $row[$id]['regnum'] = isset($reg['regnum']) ? $reg['regnum'] : 0;
            $row[$id]['pay'] = isset($payday['allmoney']) ? $payday['allmoney'] : 0;
        }

        $row['code'] = 0;
        $this->sendjsonmsg($row);
    }


    public function editeweb()
    {
        $row = $this->input->post();
        $this->load->model('Jd_config_model');

        $host = $row['host'];
        $id = $row['id'];
        unset($row['id']);
        $r = $this->Jd_config_model->update('jd_weblist', 'id', $id, $row);
        if ($r) {
            $key = "hunterweblist";
            $MYredis = $this->MyRedis();
            $sql = "select * from jd_weblist where host= '$host'";
            $res = $this->Jd_group_model->GetBySql($sql, 0);
            $res = serialize($res);
            $MYredis->hSet($key, $host, $res);
            $ttl = $MYredis->ttl($key);
            if ($ttl == -1) {
                $MYredis->expire($key, 2 * 60);
            }
            $msg['code'] = 0;
            $msg['msg'] = "修改成功";
            $this->sendjsonmsg($msg);
        }

        $msg['code'] = 1;
        $msg['msg'] = "修改失败";
        $this->sendjsonmsg($msg);

    }

    public function getweblist($type = 0)
    {
        $this->load->model('Jd_group_model');
        $MYredis = $this->MyRedis();
        $key = "weblistconfig";
        $res = $MYredis->get($key);
        $res = '';
        if (!$res) {
            $sql = "select * from jd_weblist where 1=1";
            $res = $this->Jd_group_model->GetBySql($sql, 1);
            $res = serialize($res);
            $MYredis->set($key, $res);
            $ttl = $MYredis->ttl($key);
            if ($ttl == -1) {
                $MYredis->expire($key, 2 * 60);
            }
        }
        $res = unserialize($res);


        if ($type == 1) {
            $new = array();
            foreach ($res as $id => $v) {
                $new[$v['id']] = $v['webname'];
            }
            $res = $new;
        }

        if ($type == 2) {
            $new = array();
            foreach ($res as $id => $v) {

                $new[$v['id']] = $v['ratio'];
            }
            return $new;
        }

        $msg['code'] = 0;
        $msg['list'] = $res;
        $this->sendjsonmsg($msg);
    }


    public function getwebinfolist()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $_sql = "where 1=1";
        $_select = " p1.*";
        $_order = " order by p1.id desc ";

        $sql = "select SELECT from `jd_weblist` as p1                        
                             			   SQL   ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $this->load->model('Jd_pay_log_model');
        $this->load->model('Jd_task_jd_list_model');
        $_POST['webid'] = "全部";//搜全部站点
        $result = $this->Jd_users_model->get_server_list($_data);

        $start = date("Y-m-d 00:00:00");
        $end = date("Y-m-d 23:59:59");

        $date1 = $this->input->post('date1') ? $this->input->post('date1') : false;;
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : false;
        if ($date1) {
            $start = $date1;
        }
        if ($date2) {
            $end = $date2;
        }
        foreach ($result['list'] as $id => $v) {
            $param['webid'] = $v['id'];
            $nowrow = $this->Jd_task_jd_list_model->getweekdata($start, $end, $param);
            $sendnum = $this->Jd_task_jd_list_model->getSendNumber($start, $end, $param);

            $v['sendnum'] = intval($sendnum['sendnum']);
            $v['not'] = 0;
            $v['finlish'] = 0;
            $v['profit'] = 0;
            foreach ($nowrow as $id2 => $v2) {
                if (isset($v2['all'])) {
                    $v2['all'] = intval($v2['all']);
                } else {
                    $v2['all'] = 0;
                }
                if ($v2['status'] == 0) {
                    $v['not'] += $v2['all'];
                }
                if ($v2['status'] == 1) {
                    $v['not'] += $v2['all'];
                }
                if ($v2['status'] == 2) {
                    $v['finlish'] = $v2['all'];
                    $v['profit'] = $v2['all'] ? round(($v2['gold'] - $v2['cost']) * 0.9, 2) : 0;
                    $v['profit'] = round($v['profit'] - $v2['cost3'], 2);
                    $v['profit'] = round($v['profit'] - $v2['cost4'], 2);
                    $v['profit'] = round($v['profit'] - $v2['cost5'], 2);
                    if ($v['id'] == 1) {
                        // $v['profit'] = $v2['all'] ? round(($v2['gold'] * 0.9 - $v2['cost2'] - $v2['cost3']), 2) : 0;
                    }
                }
            }
            $reg = $this->Jd_users_model->getreg($start, $end, $v['id']);
            $payday = $this->Jd_pay_log_model->getallmoney(1, "", $v['id'], $start, $end);
            $v['regnum'] = intval($reg['regnum']);
            $v['pay'] = $payday['allmoney'] ? $payday['allmoney'] : 0;
            $result['list'][$id] = $v;
        }
        //var_dump($result); exit;
        $this->sendjsonmsg($result);
    }


    /**
     * 订单检索
     */
    public function orderview()
    {
        // $this->load->model('Jd_users_model');
        $this->address = '单号检索';

        /*  $a=  $this->Jd_users_model->pageData(array('compare'=>array('id'=>1)),"*");*/
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/orderview');
    }


    /**
     * 获取订单列表
     */
    public function getorderviewlist($type = 1)
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $getexcel = $this->input->post('getexcel');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_task_jd_list_model');
        $shop_name = $this->input->post('shop_name') ? $this->input->post('shop_name') : "";

        $gexing = $this->input->post('gexing') ? $this->input->post('gexing') : "";


        $where = "  where    p1.type=$type";

        if ($gexing) {
            foreach ($gexing as $id => $v) {
                $where .= " AND p1." . $v . " >= 1";
            }
        }


        $where = $where . $this->gettimesqlstr('p1.finishtime', "start", 'end');
        $where = $where . $this->gettimesqlstr('p1.addtime');

        $where = $where . $this->getsqlstrbyrow(['taskid', 'orderid', 'hunter_name', 'status', 'type_h', 'webid', 'id', 'expressorderid']);
        $where = $where . $this->getsqlstrbyrow(['username', 'recommender_id'], "p4");


        if (!empty($shop_name)) {
            $shop_name = trim($shop_name);
            $where .= " AND p1.shop_name like '%$shop_name%'";
        }


        $_select = " p1.*,p4.username,p4.recommender,p2.text";
        $_order = " order by p1.addtime desc ";
        $sql = "select SELECT from `jd_task_jd_list` as p1                    
                 left join  `jd_users` as p4 on   p1.business_id=p4.id
                 left join `jd_text` as p2 on p1.comment=p2.id             
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);


        $a['epage'] = $epage;
        $a['page'] = $page;

        $teamlist = $this->GetCachData('getteamlist', 1);


        $type_hlist = parent::getconfig('type_h', 1);
        $liststatus = ["未接取", "被接取", "已完成", '已废除', '已废除', '申请退款', '完成退款'];
        foreach ($a['list'] as $id => $v) {
            $webid = $v['webid'];
            $costlist = parent::getconfig("cost");
            if ($webid == 1) {
                // $costlist = parent::getconfig("hostcost");
            }
            $cost = $costlist[$v['type_h']];
            $cost = round($cost * 0.9, 2);
            $a['list'][$id]['basegold'] = $cost;
            if ($v['daifa']) {
                $cost = $cost + 0.99;
            }
            if ($v['night']) {
                $cost = $cost + 1;
            }
            if ($v['dianzan']) {
                $cost = $cost + 0.25;
            }
            $a['list'][$id]['type_hname'] = $type_hlist[$v['type_h']];
            if ($v['finishtime']) {
                $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['finishtime']);
            } else {
                $a['list'][$id]['addtime'] = "";
            }

            if (!empty($v['update'])) {
                $a['list'][$id]['update'] = date('Y-m-d H:i:s', $v['update']);
            } else {
                $a['list'][$id]['update'] = "";
            }
            if ($v['chat'] > 0 || $v['compare'] > 0 || $v['collection'] > 0 || $v['sign'] > 0 || $v['overnight'] > 0 || $v['sex'] > 0 || $v['daifa'] > 0 || $v['comment'] > 0) {
                $a['list'][$id]['special'] = 1;
            }
            if ($v['dianzan'] > 0 || $v['night'] > 0) {
                $result['list'][$id]['special'] = 1;
            }
            $a['list'][$id]['money'] = $v['number'] * $v['single_price'];
            @$a['list'][$id]['teamname'] = @$v['team'] ? @$teamlist[$v['team']] : "";
            $a['list'][$id]['statusname'] = @$liststatus[$v['status']];
            $a['list'][$id]['cost'] = round($cost, 2);
            $a['list'][$id]['income'] = round($v['gold'] * 0.9 - $cost, 2);
            $a['list'][$id]['statusname'] = $liststatus[$v['status']];
        }


        if ($getexcel) {
            $str['id'] = ['ID'];
            $str['addtime'] = ['完成时间', 20];
            $str['statusname'] = ['完成状态', 15];
            $str['orderid'] = ['订单号', 30];
            $str['hunter_name'] = ['测试员'];
            $str['recommender'] = ['推荐人'];
            $str['teamname'] = ['团队'];
            $str['username'] = ['商户名', 15];
            $str['money'] = ['总本金'];
            $str['real_price'] = ['实际付款'];
            $str['taskid'] = ['任务ID'];
            $str['shop_name'] = ['店铺名', 20];
            $str['goods_name'] = ['主商品', 70];
            $str['number'] = ['总单量'];
            $str['keyword'] = ['关键字', 30];
            $str['price'] = ['录入价格'];
            $str['number'] = ['每单数量'];
            $str['gold'] = ['金币'];
            $str['cost'] = ['成本'];
            $str['income'] = ['收益'];
            $str['webid'] = ['站点ID'];
            $str['addrees'] = ['快递地址'];
            $str['express'] = ['快递公司'];
            $str['expressorderid'] = ['快递单号'];
            $this->excel_out2($str, $a['list'], "任务订单详情");
        }
        $this->sendjsonmsg($a);
    }


    public function getodergoon($type)
    {

        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_task_jd_list_model');

        $shop_name = $this->input->post('shop_name') ? $this->input->post('shop_name') : "";
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $status = $this->input->post('status') == "0" ? $this->input->post('status') : 1;
        $where = "  where  p1.status=$status  AND  p1.type=$type";


        if (!empty($shop_name)) {
            $shop_name = trim($shop_name);
            $where .= " AND p1.shop_name like '%$shop_name%'";
        }
        if (!empty($username)) {
            $username = trim($username);
            $where .= " AND p1.hunter_name= '$username'";
        }
        // echo $where; exit;

        $_select = " p1.id, p1.finishtime ,p1.addtime,p1.orderid,p1.shop_name,p1.awz,p3.name as `team`,p1.price,p1.real_price,p4.username,p2.username as 'hunter_name'";
        $_order = " order by p1.finishtime desc ";
        $sql = "select SELECT from `jd_task_jd_list_pool` as p1
                left join  `jd_users` as p2  on   p1.hunter_id=p2.id 
                 left join  `jd_team` as p3  on   p2.team=p3.id    
                 left join  `jd_users` as p4 on p1.business_id=p4.id               
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);


        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);


        //echo $this->db->last_query();die;

        //  $a=  $this->Jd_task_jd_list_model->pageData($where,"*",$page,$epage,$order);
        $a['epage'] = $epage;
        $a['page'] = $page;

        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = '';
            $a['list'][$id]['update'] = "";

        }
        $this->sendjsonmsg($a);

    }


    /**
     * 导出订单信息
     * @param $page
     * @param $eapge
     * @param $orderid
     * @param $date1
     * @param $date2
     * @param $shop_name
     */
    public function excelorderviewlist($type = 1, $date1 = "", $date2 = "", $username = "", $orderid = "", $shop_name = "")
    {

        $page = 1;
        $epage = 20000;


        if (!$date1 || $date1 == 'undefined') {
            $date1 = date('Y-m-d');
        }
        if (!$date2 || $date2 == 'undefined') {
            $date2 = date('Y-m-d');
        }

        $where = "  where  p1.status=2  AND  p1.type=$type";
        if ($date1) {
            $date1 = strtotime(date('Y-m-d 00:00:00', strtotime($date1)));
            $where .= " AND p1.finishtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime(date('Y-m-d 23:59:59', strtotime($date2)));
            $where .= " AND p1.finishtime<$date2 ";
        }

        if (!empty($orderid) && $orderid != 'undefined') {
            $where .= " AND p1.orderid= '$orderid'";
        }

        if (!empty($shop_name) && $shop_name != 'undefined') {
            $shop_name = urldecode($shop_name);
            $where .= " AND p1.shop_name= '$shop_name'";
        }
        if (!empty($username) && $username != 'undefined') {
            $username = urldecode($username);
            $where .= " AND p1.hunter_name= '$username'";
        }


        /*    '<td>' + value.id + '</td>\n' +
        '<td>' + value.addtime + '</td>\n' +
        '<td>' + value.update + '</td>\n' +
        '<td>' + value.orderid + '</td>\n' +
        '<td>   </td>\n' +
        '<td>' + value.shop_name + '</td>\n' +
        '<td>' + value.hunter_name + '</td>\n' +
        '<td>' + value.team + '</td>\n' +
        '<td>' + value.price + '</td>\n' +
        '<td>' + value.real_price + '</td>\n' +*/


        $order['id'] = "DESC";
        $_select = " p1.id,p1.addtime,p1.update,p1.orderid,p1.shop_name,p1.hunter_name,p1.awz,p3.name,p1.sku,p1.price,p1.real_price,p1.taskid ";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd_list` as p1
                left join  `jd_users` as p2  on   p1.hunter_id=p2.id 
                 left join  `jd_team` as p3  on   p2.team=p3.id                   
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);

        //echo $this->db->last_query();die;
        //  $a=  $this->Jd_task_jd_list_model->pageData($where,"*",$page,$epage,$order);
        $a['epage'] = $epage;
        $a['page'] = $page;
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);

            if (!empty($v['update'])) {
                $a['list'][$id]['update'] = date('Y-m-d H:i:s', $v['update']);
            } else {
                $a['list'][$id]['update'] = "";
            }
        }
        $str[] = 'ID';
        $str[] = '加入时间';
        $str[] = '更新时间';
        $str[] = '订单号';
        $str[] = '店铺名';
        $str[] = '测试员';
        $str[] = 'AWZ';
        $str[] = '团队';
        $str[] = 'SKU';
        $str[] = '录入价格';
        $str[] = '实际付款';
        $str[] = '任务ID';
        $this->excel_out($str, $a['list'], "测试员订单记录");

    }


    public function getpddorderlist()
    {


        $this->getorderviewlist(2);
    }


    /**
     * 商户消费记录
     */
    public function businesspaylog()
    {
        $this->address = '客户消费详情';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');

        $typelist = array();
        $typelist[0] = "全部";
        $typelist[1] = "充值";
        $typelist[2] = "发布任务";
        $typelist[3] = "推荐奖励";
        $typelist[5] = "兑换金币";
        $typelist[6] = "后台调整";
        $data['typelist'] = $typelist;


        $this->load->view('Customer/businesspaylog', $data);
    }

    /**
     * 获取商户消费记录
     */
    public function getbusinesspaylog()
    {

        $getexcel = $this->input->post('getexcel') ? $this->input->post('getexcel') : false;//判断否要导出excel
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_pay_log_model');
        $username = $this->input->post('username') ? $this->input->post('username') : "";

        $user_type = $this->input->post('group') ? $this->input->post('group') : "";

        $type = $this->input->post('type') ? $this->input->post('type') : "";
        $where = "  where 1=1  ";

        if ($this->group != 1) {
            $where .= " AND p1.user_id=" . intval($this->user_id);
        }

        if (!empty($username)) {
            $where .= " AND  p2.username= '$username'";
        }
        if (!empty($user_type)) {
            $where .= " AND  p1.user_type=$user_type ";
        }

        if (!empty($type)) {
            $where .= " AND  p1.type= $type";
        }
        $where = $where . $this->gettimesqlstr("p1.addtime");
        $where = $where . $this->getsqlstrbyrow(["recommender_id"], "p2");
        $where = $where . $this->getsqlstrbyrow(["webid"]);
        $order['id'] = "DESC";
        $_select = " p1.*,p2.username,p3.number,p2.recommender";
        if ($getexcel) {
            $_select = " p1.id,p2.username,p2.recommender,p1.type,p1.capital,p1.money,p1.balance,p1.capital_gold,p1.gold,p1.balance_gold,p1.addtime,p1.balance,p1.balance,p1.balance,p3.number,p1.log_id";
        }
        $_order = " order by p1.id desc ";

        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id      
                 left join  `jd_task_jd` as p3  on   p1.log_id=p3.id  AND p1.type=2     
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        $typelist = parent::getconfig('paylog_type');
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            $a['list'][$id]['type'] = $typelist[$v['type']];
            if ($v['type'] != 2) {
                $a['list'][$id]['number'] = "-";
            }
        }

        if ($getexcel) {
            $str[] = 'ID';
            $str[] = '用户名';
            $str[] = '推荐人';
            $str[] = '类型';
            $str[] = '本金';
            $str[] = '变动资金';
            $str[] = '余额';
            $str[] = '原有金币';
            $str[] = '金币变动';
            $str[] = '剩余金币';
            $str[] = '时间';
            $str[] = '单量';
            $str[] = '任务或日志ID';
            $this->excel_out($str, $a['list'], "商户资金记录");

        }


        $a['allmoney'] = $this->getallsend();
        $this->sendjsonmsg($a);
    }


    /**
     * 获取当日全部任务本金
     */
    public function getallsend()
    {
        $this->load->model('Jd_pay_log_model');
        $all = $this->Jd_pay_log_model->getallmoney();
        if (empty($all)) {
            return 0;
        }
        return -$all['allgold'];
    }


    public function viewSaleall()
    {

        $this->address = '销售总计数据';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/Saletotal');

    }

    /**
     * 获取销售近期所有记录
     */
    public function getSaleall()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_pay_log_model');
        $recommender = $this->input->post('recommender') ? $this->input->post('recommender') : "";
        $recommender = trim($recommender);
        $where = "  where   p2.recommender_id>0  AND  (p1.type=2 or p1.type=1) ";
        $where2 = "where 1=1";
        //$date1='2020-03-01';
        $alllist = array();
        $where = $where . $this->gettimesqlstr('p1.addtime');
        $where2 = $where2 . $this->gettimesqlstr('p1.addtime');

        $where = $where . $this->getsqlstrbyrow(['recommender'], "p2");
        $where = $where . $this->getsqlstrbyrow(['recommender'], "p2");


        if (!empty($recommender)) {
            $where .= " AND  p2.recommender= '$recommender'";
            $where2 .= " AND username='$recommender'";
        }
        $order['id'] = "DESC";
        $_select = "p1.type,sum(p3.number)as 'number', sum(p1.money) as 'money' ,p2.recommender,p2.recommender_id ";
        $_order = " ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id      
                 left join  `jd_task_jd` as p3  on   p1.log_id=p3.id                
				 SQL   group by	p2.recommender,p1.type ,p2.recommender_id ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id => $v) {
            switch ($v['type']) {
                case 1 :
                    $a['list'][$id]['type'] = '充值';
                    break;
                case 2 :
                    $a['list'][$id]['type'] = '发布任务';
                    break;
                case 3 :
                    $a['list'][$id]['type'] = '推荐奖励';
                    break;
                case 4 :
                    $a['list'][$id]['type'] = '测试员刷单';
                    break;
                case 5 :
                    $a['list'][$id]['type'] = '兑换金币';
                    break;
                case 6 :
                    $a['list'][$id]['type'] = '后台调整';
                    break;
            }
            if ($v['type'] != 2) {
                $a['list'][$id]['number'] = "-";
            } else {
                $a['list'][$id]['money'] = 0;
            }

        }


        foreach ($a['list'] as $id => $v) {
            $newv = array();
            if ($v['type'] == "发布任务") {
                $newv['name'] = $v['recommender'];
                $newv['number'] = $v['number'];
                $newv['money'] = 0;
                $newv['reg'] = 0;
            }
            $alllist[$v['recommender_id']] = $newv;
        }


        foreach ($a['list'] as $id => $v) {
            $newv = array();
            if ($v['type'] == "充值") {
                $newv['name'] = $v['recommender'];
                $newv['money'] = $v['money'];
                $newv['number'] = 0;
                $newv['reg'] = 0;

                if (isset($alllist[$v['recommender_id']])) {
                    $alllist[$v['recommender_id']]['money'] = $v['money'];
                } else {
                    $alllist[$v['recommender_id']] = $newv;
                }
            }
        }

        $sql = "select count(1) as 'reg',username,user_id  from  jd_recommended_log " . $where2 . "
group by 	username,user_id 
";
        $this->load->model('Jd_Recommended_log');
        $tuijianlist = $this->Jd_Recommended_log->getusertuijian($sql);
        foreach ($tuijianlist as $id => $v) {
            if (isset($alllist[$v['user_id']])) {
                $alllist[$v['user_id']]['reg'] = $v['reg'];
            } else {
                $newv = array();
                $newv['name'] = $v['username'];
                $newv['money'] = 0;
                $newv['number'] = 0;
                $newv['reg'] = $v['reg'];
                $alllist[$v['user_id']] = $newv;
            }

        }

        $lsit = array();

        foreach ($alllist as $id => $v) {
            $lsit['list'][] = $v;
        }
        $lsit['total'] = count($alllist);
        $lsit['page'] = 1;
        $lsit['epage'] = count($alllist);
        $this->sendjsonmsg($lsit);
    }


    /**
     * 测试员资金记录
     */
    public function hunterpaylog()
    {
        $this->address = '测试员消费详情';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/hunterpaylog');
    }


    public function hunterpaylogexcel($date1 = "", $date2 = "", $username = "")
    {
        $page = 1;
        $epage = 2000;
        $this->load->model('Jd_pay_log_model');
        $_sql = " where  user_type=3 ";
        if ($date1 && $date1 != "undefined") {
            $date1 = strtotime($date1);
            $_sql .= " AND  p1.addtime>$date1 ";
        }
        if ($date2 && $date2 != "undefined") {
            $date2 = strtotime($date2);
            $_sql .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username) && $username != "undefined") {
            $username = urldecode($username);

            $_sql .= " AND  p2.username= '$username'";
        }
        $order['id'] = "DESC";
        $_select = " p1.id,p2.username,p1.type,p1.capital,p1.money,p1.balance,p1.capital_gold,p1.gold,p1.balance_gold,p1.addtime,p1.balance,p1.balance,p1.balance";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id        
                          
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            switch ($v['type']) {
                case 1 :
                    $a['list'][$id]['type'] = '充值';
                    break;
                case 2 :
                    $a['list'][$id]['type'] = '发布任务';
                    break;
                case 3 :
                    $a['list'][$id]['type'] = '推荐奖励';
                    break;
                case 4 :
                    $a['list'][$id]['type'] = '测试员刷单';
                    break;
                case 5 :
                    $a['list'][$id]['type'] = '兑换金币';
                    break;
                case 6 :
                    $a['list'][$id]['type'] = '后台调整';
                    break;
            }
        }
        $str[] = 'ID';
        $str[] = '用户名';
        $str[] = '类型';
        $str[] = '本金';
        $str[] = '变动资金';
        $str[] = '余额';
        $str[] = '原有金币';
        $str[] = '金币变动';
        $str[] = '剩余金币';
        $str[] = '时间';
        $this->excel_out($str, $a['list'], "测试员资金记录");
    }


    /**
     * 商户资金记录导出
     * @param string $date1
     * @param string $date2
     * @param string $username
     * @throws PHPExcel_Exception
     * @throws PHPExcel_Writer_Exception
     */
    public function businesspaylogexcel($date1 = "", $date2 = "", $username = "", $type = "", $recommender = "")
    {
        $page = 1;
        $epage = 2000;
        $this->load->model('Jd_pay_log_model');
        $_sql = " where  user_type=2 ";
        if ($date1 && $date1 != "undefined") {
            $date1 = strtotime($date1);
            $_sql .= " AND  p1.addtime>$date1 ";
        }
        if ($date2 && $date2 != "undefined") {
            $date2 = strtotime($date2);
            $_sql .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username) && $username != "undefined") {
            $username = urldecode($username);
            $_sql .= " AND  p2.username= '$username'";
        }

        if (!empty($recommender) && $recommender != "undefined") {
            $recommender = urldecode($recommender);
            $_sql .= " AND  p2.recommender= '$recommender'";
        }

        if (!empty($type)) {
            $_sql .= " AND  p1.type= $type";
        }
        $order['id'] = "DESC";
        $_select = " p1.id,p2.username,p2.recommender,p1.type,p1.capital,p1.money,p1.balance,p1.capital_gold,p1.gold,p1.balance_gold,p1.addtime,p1.balance,p1.balance,p1.balance,p3.number";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id   
                       left join  `jd_task_jd` as p3  on   p1.log_id=p3.id  AND p1.type=2                    
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            switch ($v['type']) {
                case 1 :
                    $a['list'][$id]['type'] = '充值';
                    break;
                case 2 :
                    $a['list'][$id]['type'] = '发布任务';
                    break;
                case 3 :
                    $a['list'][$id]['type'] = '推荐奖励';
                    break;
                case 4 :
                    $a['list'][$id]['type'] = '测试员刷单';
                    break;
                case 5 :
                    $a['list'][$id]['type'] = '兑换金币';
                    break;
                case 6 :
                    $a['list'][$id]['type'] = '后台调整';
                    break;
            }
        }
        $str[] = 'ID';
        $str[] = '用户名';
        $str[] = '推荐人';
        $str[] = '类型';
        $str[] = '本金';
        $str[] = '变动资金';
        $str[] = '余额';
        $str[] = '原有金币';
        $str[] = '金币变动';
        $str[] = '剩余金币';
        $str[] = '时间';
        $str[] = '单量';
        $this->excel_out($str, $a['list'], "商户资金记录");

    }

    public function gethunterpaylog()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_pay_log_model');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $date1 = $this->input->post('date1') ? $this->input->post('date1') : "";
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : "";
        $_sql = " where  user_type=3 ";
        if ($date1) {
            $date1 = strtotime($date1);
            $_sql .= " AND  p1.addtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime($date2);
            $_sql .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username)) {
            $_sql .= " AND  p2.username= '$username'";
        }
        $order['id'] = "DESC";
        $_select = " p1.*,p2.username";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_pay_log` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id                  
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            switch ($v['type']) {
                case 1 :
                    $a['list'][$id]['type'] = '充值';
                    break;
                case 2 :
                    $a['list'][$id]['type'] = '发布任务';
                    break;
                case 3 :
                    $a['list'][$id]['type'] = '推荐奖励';
                    break;
                case 4 :
                    $a['list'][$id]['type'] = '测试员刷单';
                    break;
                case 5 :
                    $a['list'][$id]['type'] = '兑换金币';
                    break;
                case 6 :
                    $a['list'][$id]['type'] = '后台调整';
                    break;
            }
        }


        $this->sendjsonmsg($a);

    }


    /**
     * 欠费用户列表页
     */
    public function owemoney()
    {
        $this->address = '欠费用户列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/ownmoney');
    }


    /**
     * 获取拥有欠款的商户
     */
    public function geyowemoneylist()
    {
        $this->load->model('Jd_buniess_balance_model');
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        if (empty($epage)) {
            $epage = 10;
        }
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $date = $this->input->post('date') ? $this->input->post('date') : "";
        $date1 = $this->input->post('date1') ? $this->input->post('date1') : "";
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : "";
        $date = date('Y-m-d');
        $where = " 1=1  ";
        if ($date) {
            // $where.=" AND date='$date' ";
        }
        if ($date1) {
            $date1 = strtotime($date1);
            $where .= " AND addtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime($date2);
            $where .= " AND addtime<$date2 ";
        }
        if (!empty($username)) {
            $where .= " AND username= $username";
        }
        $order['id'] = "DESC";
        $row = $this->Jd_buniess_balance_model->pageData($where, "*", $page, $epage, $order);
        $this->load->model('Jd_users_model');
        /*   foreach ($row['list'] as $id=>$v){
            if(empty($v['username'])){
               $userinfo= $this->Jd_users_model->GetUserById( $v['user_id']);
            }
        }*/
        $row['epage'] = $epage;
        $row['page'] = $page;
        $this->sendjsonmsg($row);
    }


    /**
     * excel导出欠款用户
     * @param $date1
     * @param $date2
     * @param $username
     */
    public function GetExcleOwemoneyList($date1, $date2, $username)
    {
        $this->load->model('Jd_buniess_balance_model');
        $page = 1;
        $epage = 2000;

        $date = date('Y-m-d');
        $date = "";

        $where = " 1=1  ";
        if ($date) {
            $where .= " AND date='$date' ";
        }
        if ($date1 && $date1 != 'undefined') {
            $date1 = strtotime($date1);
            $where .= " AND addtime>$date1 ";
        }
        if ($date2 && $date2 != 'undefined') {
            $date2 = strtotime($date2);
            $where .= " AND addtime<$date2 ";
        }
        if (!empty($username) && $username != 'undefined') {
            $username = urldecode($username);
            $where .= " AND username= $username";
        }
        $order['id'] = "DESC";
        $select = "id,username,saler,money,gold,balance,`date`";
        $row = $this->Jd_buniess_balance_model->pageData($where, $select, $page, $epage, $order);
        $str[] = 'ID';
        $str[] = '用户名+';
        $str[] = '销售';
        $str[] = '总本金';
        $str[] = '总金币';
        $str[] = '余额';
        $str[] = '日期';
        $this->excel_out($str, $row['list'], "欠款用户列表");
    }


    /**
     * 查看京东任务列表
     */
    public function pddorderview()
    {
        $this->address = '拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddorderview');
    }

    /**
     * 查看拼多多任务列表
     */
    public function pddtasklist()
    {
        $this->address = '拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddtasklist');
    }


    public function relodpddtask($id)
    {

        $this->address = '拼多多任务修改';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');

        $this->load->model('Jd_task_jd_model');
        $row = $this->Jd_task_jd_model->getonebyid($id);
        $str = explode("/", $row['picurl']);
        if (isset($str[1]) && $str[1] == 'pic') {
            $row['picurl'] = base_url() . "public/uploads" . $row['picurl'];
        }

        $type_h_number = $this->getconfig("type_h_number");
        $row['min'] = $type_h_number['min'];
        $row['max'] = $type_h_number['max'];
        $row['is12'] = 0;

        if (time() > strtotime(date('Y-m-d 12:00:00'))) {
            $row['is12'] = 1;
        }

        $this->load->view('Customer/relodpddtask', $row);
    }


    /**
     * 查看京东任务列表
     */
    public function pddtasksort()
    {
        $this->address = '拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/pddtasksort');
    }


    /**
     * 查看京东任务列表
     */
    public function jdtasklist()
    {
        $this->address = '京东任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jdtasklist');
    }


    /**
     * 测试员管理
     */
    public function Hunter()
    {
        $this->address = '测试员管理';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/hunter');
    }


    /**
     * 获取测试员列表
     */
    public function gethunterlist()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $date = $this->input->post('date') ? $this->input->post('date') : "";
        if (!$date) {
            $date = date('Y-m-d');
        }
        $month = date('Y-m-1', strtotime($date));
        $_sql = "where p1.`group`=3 ";

        $serachRow = ["id", 'username', 'phone', 'channel', 'team'];
        $_sql = $_sql . $this->getsqlstrbyrow($serachRow);
        if (!empty($username)) {
            $_sql .= " AND p1.username= '$username'";
        }
        $_select = " p1.*,p2.usemoney,p2.sendmoney,p2.finishnub as 'finishnubday',p3.finishnub,p3.usemoney as  `usemoneymonth`";
        $_order = " order by p2.finishnub desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_hunter_total_day` as p2  on   p1.id=p2.user_id  AND p2.`date`='$date'
                 left join  `jd_hunter_total_month` as p3  on   p1.id=p3.user_id      AND p3.`date`='$month'             
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);
        $teamlist = $this->GetCachData('getteamlist', 1);
        $channellist = $this->GetCachData('getchannellist', 1);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['password'] = "";
            $result['list'][$id]['usemoney'] = $v['usemoney'];
            $result['list'][$id]['sendmoney '] = $v['sendmoney'];
            $result['list'][$id]['teamname'] = $v['team'] ? $teamlist[$v['team']] : "";
            $result['list'][$id]['channelname'] = $v['channel'] ? $channellist[$v['channel']] : "";
            $result['list'][$id]['goldday'] = $v['finishnubday'] * 1.5;
            $result['list'][$id]['goldmonth'] = $v['finishnub'] * 1.5;
        }
        $this->sendjsonmsg($result);
    }


    /**
     * 获取商户列表列表
     */
    public function GetBusinessList()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $phone = $this->input->post('phone') ? $this->input->post('phone') : "";

        $date = $this->input->post('date') ? $this->input->post('date') : "";
        if (!$date) {
            $date = date('Y-m-d');
        }
        $month = date('Y-m-1', strtotime($date));
        $_sql = "where p1.`group`=2 ";
        if (!empty($phone)) {
            $_sql .= " AND p1.phone= '$phone'";
        }
        if ($this->input->post('channel')) {
            $channel = $this->input->post('channel');
            $_sql .= " AND p1.channel= $channel";
        }
        if ($this->input->post('team')) {
            $team = $this->input->post('team');
            $_sql .= " AND p1.team= $team";
        }
        if ($this->input->post('id')) {
            $id = $this->input->post('id');
            $_sql .= " AND p1.id= $id";
        }
        if ($this->input->post('recommender_id')) {
            $recommender_id = $this->input->post('recommender_id');
            $_sql .= " AND p1.recommender_id= $recommender_id";
        }
        if ($this->input->post('VIP')) {
            $VIP = $this->input->post('VIP');
            $_sql .= " AND p1.VIP= $VIP";
        }
        $_sql .= $this->getsqlstrbyrow(['webid']);


        $_sql .= $this->gettimesqlstr('p1.regtime');

        if ($username) {

            $_sql .= " AND p1.username= '$username'";
        }


        $_select = " p1.*,p2.task_nub,p2.allmoney,p2.allgold";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_user_total` as p2  on   p1.id=p2.user_id                
                             
			   SQL   ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');


        $result = $this->Jd_users_model->get_server_list($_data);


        foreach ($result['list'] as $id => $v) {

            $result['list'][$id]['task_nub'] = $v['task_nub'] ? $v['task_nub'] : 0;
            $result['list'][$id]['allmoney'] = $v['allmoney'] ? $v['allmoney'] : 0;
            $result['list'][$id]['allgold'] = $v['allgold'] ? $v['allgold'] : 0;


            //   $result['list'][$id]['money']=$v['pay_price']*$v['number']*$v['each_single'];
            $result['list'][$id]['status'] = $v['status'] == 0 ? '禁用中' : '正常';
        }
        $this->sendjsonmsg($result);
    }


    /**
     * 获取用户列表列表
     */
    public function GetALLuserList()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $_sql = "where 1=1 ";
        $_sql = $_sql . $this->getsqlstrbyrow(['id', 'username', 'recommender', 'recommender_id', 'phone', 'channel', 'team', 'group', 'webid']);
        $_sql .= $this->gettimesqlstr('p1.regtime');
        $taskdate1 = $this->input->post('taskdate1') ? $this->input->post('taskdate1') : '';
        $taskdate2 = $this->input->post('taskdate2') ? $this->input->post('taskdate2') : '';

        $_select = " p1.*,p2.task_nub,p2.task_nub_finnish,p2.extension_nub,p2.extension_nub_day,p2.allmoney,p2.allgold,p2.extension_nub_day,p2.update";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1      
          left  join `jd_user_total` as p2 on p1.id=p2.user_id           
SQL    ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $this->load->model('Jd_task_jd_list_model');

        $result = $this->Jd_users_model->get_server_list($_data);


        $teamlist = $this->GetCachData('getteamlist', 1);
        $channellist = $this->GetCachData('getchannellist', 1);
        $grouplist = $this->GetCachData('getgrouplist', 1);
        $data = date('Y-m-d');
        foreach ($result['list'] as $id => $v) {
            /*  if(!empty($v['newtime'])){
                $result['list'][$id]['newtime']=date('Y-m-d H:i:s',$v['newtime']);
            }else{
                $result['list'][$id]['newtime']="";
            }*/
            $result['list'][$id]['regtime'] = date('Y-m-d H:i:s', $v['regtime']);
            $result['list'][$id]['type'] = @$grouplist[$v['group']];
            $result['list'][$id]['teamname'] = $v['team'] ? $teamlist[$v['team']] : "";
            $result['list'][$id]['channelname'] = $v['channel'] ? $channellist[$v['channel']] : "";
            //   $result['list'][$id]['money']=$v['pay_price']*$v['number']*$v['each_single'];
            $result['list'][$id]['status'] = $v['status'] == 0 ? '禁用中' : '正常';
            if ($this->web_id != 1) {
                $result['list'][$id]['password'] = '';
            }
            if ($v['update'] != $data) {
                $result['list'][$id]['extension_nub_day'] = 0;
            }
            $result['list'][$id]['link'] = $this->SetExtensionLink($v['id']);
            $result['list'][$id]['link'] = str_replace("admin", 'www', $result['list'][$id]['link']);


            $pare['salaid'] = $v['id'];
            $pare['webid'] = $v['webid'];

            $costrow = $this->Jd_task_jd_list_model->getcost($taskdate1, $taskdate2, $pare);

            //var_dump($costrow); exit;

            $result['list'][$id]['profit'] = isset($costrow['all']) ? round(($costrow['gold'] - $costrow['cost']) * 0.9, 2) : 0;
            $result['list'][$id]['profit'] = round($result['list'][$id]['profit'] - $costrow['cost3'], 2);
            $result['list'][$id]['profit'] = round($result['list'][$id]['profit'] - $costrow['cost4'], 2);
            $result['list'][$id]['profit'] = round($result['list'][$id]['profit'] - $costrow['cost5'], 2);


            $rate = $v['rate'];
            $result['list'][$id]['profit'] = round($result['list'][$id]['profit'] * $rate, 2);
            $result['list'][$id]['tasknum'] = $costrow['all'];
        }
        $this->sendjsonmsg($result);
    }


    /**
     * 获取京东(拼多多)任务列表
     */
    public function getjdtasklist($type = 1, $show = 0, $issrot = false)
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $getexcel = $this->input->post('getexcel') ? $this->input->post('getexcel') : false;//判断否要导出excel
        $time = time();
        $_sql = "where  p1.type=$type ";

        if ($show == 0) {
            $_sql .= " AND (`releasetime` is null  or `issend`=1 or `releasetime`=0)";
        }
        $gexing = $this->input->post('gexing') ? $this->input->post('gexing') : "";

        if ($gexing) {
            foreach ($gexing as $id => $v) {
                if ($id == 'textpath') {
                    $_sql .= " AND (p1.textpath <>'')";
                } else {
                    $_sql .= " AND p1." . $v . " >= 1";
                }
            }

        }
        $team = $this->input->post('team') ? $this->input->post('team') : "";

        if ($team) {
            $_sql .= " AND  locate($team,p1.`team`) ";
        }

        // echo $_sql;exit;

        $_sql = $_sql . $this->getsqlstrbyrow(['id', 'type_h'], "p1");
        $_sql = $_sql . $this->getsqlstrbyrow(['username'], "p2");
        $_sql = $_sql . $this->getsqlstrbyrow(['shop_name', 'keyword', 'status', 'webid']);
        $_sql = $_sql . $this->gettimesqlstr();
        $_select = " p1.*,p2.username,p2.salername";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd` as p1             
            left join jd_users as p2 on p2.id=p1.business_id 
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');


        $result = $this->Jd_task_jd_model->get_server_list($_data);
        $pay_type[1] = '全部开团';
        $pay_type[2] = '单独购买';
        $pay_type[3] = '优先参团';

        $type_hlist = parent::getconfig('type_h', 1);
        $costlist = parent::getconfig('cost', 1);

        if ($this->web_id == 1) {
            //$costlist = parent::getconfig("hostcost");
            //$costlist = [1=>1.5,2=>2,3=>1.5,4=>2,];
        }

        $statuslist = ["未发布", "已发布", "任务中", "已完成", "已废除"];

        foreach ($result['list'] as $id => $v) {
            $webid = $v['webid'];
            $cost = $costlist[$v['type_h']];
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            $result['list'][$id]['money'] = round($v['pay_price'] * $v['number'] * $v['each_single'], 2);
            $result['list'][$id]['number'] = $v['finish_nub'] . "/" . $v['number'];
            $result['list'][$id]['Surplus'] = $v['number'] - $v['finish_nub'];
            $result['list'][$id]['type_hname'] = $type_hlist[$v['type_h']];
            $result['list'][$id]['releasetime'] = $v['releasetime'] ? date('Y-m-d H:i:s', $v['releasetime']) : "";
            @$result['list'][$id]['pay_type'] = $pay_type[$v['pay_type']];
            if ($v['releasetime'] && $v['status'] == 1 && $v['issend'] != 1) {
                $result['list'][$id]['status'] = 0;
            }
            $result['list'][$id]['releasetime'] = $v['releasetime'] ? date('Y-m-d H:i:s', $v['releasetime']) : "";
            $result['list'][$id]['statusname'] = $statuslist[$v['status']];
            $result['list'][$id]['team'] = $v['team'] ? explode(",", $v['team']) : [];
            $sexname = "";
            if ($v['sex'] == 1) {
                $sexname = "男号";
            }
            if ($v['sex'] == 2) {
                $sexname = "女号";
            }
            $result['list'][$id]['sexname'] = $sexname;
            $result['list'][$id]['special'] = 0;
            if ($v['chat'] > 0 || $v['compare'] > 0 || $v['collection'] > 0 || $v['sign'] > 0 || $v['overnight'] > 0 || $v['sex'] > 0 || $v['daifa'] > 0 || $v['textpath'] != "") {
                $result['list'][$id]['special'] = 1;
            }
            if ($v['dianzan'] > 0 || $v['night'] > 0) {
                $result['list'][$id]['special'] = 1;
            }

            //$result['list'][$id]['cost'] = $webid== 1 ? $cost : round($cost * 0.9, 1);
            //$result['list'][$id]['income'] = $webid== 1 ? round($v['gold'] - $cost, 1) : round(($v['gold'] - $cost) * 0.9, 1);


            if ($v['dianzan']) {
                $cost = $cost + 0.25;
            }
            if ($v['night']) {
                $cost = $cost + 1;
            }

            if ($v['daifa']) {
                $result['list'][$id]['cost'] = round($cost * 0.9, 1) + 0.99;
                $result['list'][$id]['income'] = round(($v['gold'] - $cost) * 0.9, 1) - 0.99;
            } else {
                $result['list'][$id]['cost'] = round($cost * 0.9, 1);
                $result['list'][$id]['income'] = round(($v['gold'] - $cost) * 0.9, 1);
            }

            $result['list'][$id]['cost'] = round($result['list'][$id]['cost'] * $v['number'], 2);
            $result['list'][$id]['income'] = round($result['list'][$id]['income'], 2);


        }
        if ($getexcel) {
            $str['id'] = ['ID'];
            $str['username'] = ['用户名', 16];
            $str['addtime'] = ['加入时间', 20];
            $str['releasetime'] = ['定时', 20];
            $str['statusname'] = ['状态'];
            $str['type_hname'] = ['类型'];
            $str['goods_name'] = ['主商品', 70];
            $str['number'] = ['总单量'];
            $str['keyword'] = ['关键字', 30];
            $str['shop_name'] = ['商铺名', 20];
            $str['each_single'] = ['每单数量'];
            $str['pay_price'] = ['单个价格'];
            $str['pay_type'] = ['拼团'];
            $str['money'] = ['本金'];
            $str['gold'] = ['金币'];
            $str['cost'] = ['成本'];
            $str['income'] = ['收益'];
            $str['webid'] = ['站点'];
            $this->excel_out2($str, $result['list'], "任务列表");
        }
        $this->sendjsonmsg($result);

    }


    public function getjdtasklistexcel($type = 1, $date1 = "", $date2 = "", $username = "", $shop_name = "", $status = "")
    {

        $page = 1;
        $epage = 20000;
        $_sql = "where  p1.type=$type";

        $date1 = $date1 ? $date1 : date('Y-m-d');
        $date2 = $date2 ? $date2 : date('Y-m-d');

        if ($date1) {
            $date1 = strtotime(date('Y-m-d 00:00:00', strtotime($date1)));
            $_sql .= " AND p1.addtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime(date('Y-m-d 23:59:59', strtotime($date2)));
            $_sql .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username)) {
            $username = urldecode($username);
            $_sql .= " AND p2.username= '$username'";
        }
        if (!empty($shop_name)) {


            $shop_name = urldecode($shop_name);
            $_sql .= " AND p1.shop_name= '$shop_name'";
        }


        if (!empty($status)) {
            $_sql .= " AND p1.status= $status";
        }


        $_select = " p1.id,p1.addtime,p1.goods_name,p1.finish_nub,p1.number,p1.keyword,p1.shop_name,p1.each_single,pay_price,pay_type";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd` as p1             
            left join jd_users as p2 on p2.id=p1.business_id 
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);


        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            switch ($v['pay_type']) {
                case 1:
                    $result['list'][$id]['pay_type'] = '全部开团';
                    break;
                case 2:
                    $result['list'][$id]['pay_type'] = '单独购买';
                    break;
                case 3:
                    $result['list'][$id]['pay_type'] = '优先参团';
                    break;
            }
        }
        $str[] = 'ID';
        $str[] = '加入时间';
        $str[] = '主商品';
        $str[] = '完成单';
        $str[] = '总单量';
        $str[] = '关键字';
        $str[] = '商铺名';
        $str[] = '每单数量';
        $str[] = '录入价格';
        $str[] = '拼团';
        $this->excel_out($str, $result['list'], "今日任务列表");
    }


    /**
     * 京东任务排序
     */
    public function jdtasksort()
    {

        $this->address = '京东任务排序';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jdtasksort');

    }


    /**
     * 设置任务子单推送间隔
     */
    public function SetTaskInterval()
    {

        $id = $this->input->post('id');
        $value = $this->input->post('value');
        $type = $this->input->post('type') ? $this->input->post('type') : 1;
        $team = $this->input->post('team') ? $this->input->post('team') : 0;
        $value = intval($value);
        $id = intval($id);
        $this->load->model('Jd_task_jd_model');
        if ($type == 1) {
            $res = $this->checktaskteam($id, $team);
            if ($res['code'] != 0) {
                $this->sendjsonmsg($res);
            }

            $result = $this->Jd_task_jd_model->UpdateStatus($id, 2);
            if ($team) {
                $team = implode(",", $team);
            } else {
                $team = "";
            }
            $result = $this->Jd_task_jd_model->UpdatelastSendInterval($id, $value, $team);


            if ($team) {
                $this->load->model('Jd_task_jd_list_pool_model');
                $row['id'] = $id;
                $row['team'] = $team;
                $this->Jd_task_jd_list_pool_model->taskupdate($row);
            }
        }
        if ($type == 2) {
            $result = $this->Jd_task_jd_model->UpdateStatus($id, 1);
        }
        if ($result) {
            $msgp['msg'] = "设置成功";
            $this->sendjsonmsg($msgp);
        }
        $msgp['code'] = 1;
        $msgp['msg'] = "设置失败";
        $this->sendjsonmsg($msgp);
    }

    public function checktaskteam($id, $team)
    {
        $msg['code'] = 0;
        $this->load->model('Jd_task_jd_model');
        $res = $this->Jd_task_jd_model->getonebyid($id);
        $teamlist = $this->getteamlist(1);
        if (!is_array($team)) {
            $team = explode(",", $team);
        }

        if ($res['type_h'] == 2 && empty($team)) {
            $msg['code'] = 1;
            $msg['msg'] = "高留评单必须指定团队";
        }
        if (in_array(2, $team) && $res['sign']) {
            $msg['code'] = 1;
            $msg['msg'] = $teamlist[2] . "无法接收签收单";
        }
        return $msg;
    }


    public function TaskCancel()
    {
        $id = $this->input->post('id');
        $id = intval($id);
        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->UpdateStatus($id, 4);
        if ($result) {
            $this->load->model('Jd_task_jd_list_model');
            $result = $this->Jd_task_jd_list_model->CancelStatus($id);
            if ($result) {
                $this->load->model('Jd_task_jd_list_pool_model');
                $this->Jd_task_jd_list_pool_model->CancelStatus($id);
            }
            if ($result) {
                $msgp['msg'] = "设置成功";
                $this->sendjsonmsg($msgp);
            }
        }
        $msgp['code'] = 1;
        $msgp['msg'] = "设置失败";
        $this->sendjsonmsg($msgp);
    }


    /**
     * 重置任务
     */
    public function ResetStatus()
    {
        $id = $this->input->post('id');
        $this->load->model('Jd_task_jd_list_pool_model');
        $id = intval($id);
        $result = $this->Jd_task_jd_list_pool_model->ResetStatus($id);
        if ($result) {
            $msgp['msg'] = "重置成功";
            $this->sendjsonmsg($msgp);
        }
        $msgp['code'] = 1;
        $msgp['msg'] = "重置失败";
        $this->sendjsonmsg($msgp);
    }


    /**
     * $type :推送类型 1京东  2 拼多多
     * 推送任务至任务池中
     */
    public function sendtask($type = 1)
    {
        $this->load->model('Jd_task_jd_model');
        $row = $this->Jd_task_jd_model->getwaittask();
        if (empty($row)) {
            $msg['code'] = 1;
            $msg['msg'] = "没有待推送的任务";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_task_jd_list_model');
        $this->load->model('Jd_task_jd_list_pool_model');
        $idlist = array();
        $taskidstr = array();
        $this->db->trans_begin();
        foreach ($row as $key => $value) {
            $taskid = $value['id'];
            $interval = $value['interval'];
            $lastsendtime = $value['lastsendtime'] ? $value['lastsendtime'] : 0;
            $realinterval = intval(time() - $lastsendtime) / 60;
            if ($realinterval < $interval) {
                continue;
            }
            $listrow = $this->Jd_task_jd_list_model->getminlitstake($taskid);
            $listrow['listid'] = $listrow['id'];
            unset($listrow['id']);
            $listrow['addtime'] = time();
            unset($listrow['hunter_id']);
            unset($listrow['hunter_name']);
            unset($listrow['team']);
            $listrow['shop_name'] = $value['shop_name'];
            $r = $this->Jd_task_jd_list_pool_model->addtasklisttopoll($listrow);
            if ($r) {
                $idlist[] = $listrow['listid'];
                $taskidstr[] = $taskid;
            }
        }
        if (!empty($idlist)) {
            $result = $this->Jd_task_jd_list_model->updatapool($idlist);
            if ($result) {
                $result = $this->Jd_task_jd_model->UpdatelastSendTime($taskidstr);
                if ($result) {
                    $this->db->trans_commit();
                    $msg['code'] = 0;
                    $msg['msg'] = "推送成功";
                    $this->sendjsonmsg($msg);
                }
            }
        } else {
            $msg['code'] = 1;
            $msg['msg'] = "没有合适任务或推送失败";
            $this->sendjsonmsg($msg);
        }
    }


    /**
     * 充值审核列表
     */
    public function paylimit()
    {
        $this->address = '充值审核列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/paylimit');
    }


    public function payfinish()
    {
        $this->address = '充值完成列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/payfinish');
    }

    /**
     * 获取充值列表
     */
    public function getpaylistaction()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');

        $type = $this->input->post('type');

        if (empty($epage)) {
            $epage = 10;
        }

        $status = $this->input->post('status');
        $where = "where 1=1 ";
        if (isset($status) && $status != "") {
            $where .= " AND p1.status= $status";
        }

        $where = $where . $this->getsqlstrbyrow(['id', 'username', 'phone'], "p2");
        $where = $where . $this->gettimesqlstr("p1.addtime");
        $this->load->model('Jd_pay_model');
        $_order = 'order by p1.id desc';
        $_select = "p1.*,p2.username,p2.recommender,p2.phone";
        $sql = "select SELECT from `jd_pay` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id              
                             			   SQL    ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_pay_model');
        $result = $this->Jd_pay_model->get_server_list($_data);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            $result['list'][$id]['picurl'] = base_url() . "public/uploads" . $v['picurl'];
            switch ($v['status']) {
                case 0:
                    $result['list'][$id]['status'] = '待审核';
                    break;
                case 1:
                    $result['list'][$id]['status'] = '已通过';
                    break;
                case 2:
                    $result['list'][$id]['status'] = '已拒绝';
                    break;
            }
        }

        $this->sendjsonmsg($result);
    }


    /**
     * 获取退款申请列表
     */
    public function getrefundaction()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $type = $this->input->post('type');
        if (empty($epage)) {
            $epage = 10;
        }
        $status = $this->input->post('status');
        $where = "where 1=1 ";
        if (isset($status) && $status != "") {
            $where .= " AND p1.status= $status";
        }

        $where = $where . $this->getsqlstrbyrow(['id', 'username', 'phone'], "p2");
        $where = $where . $this->gettimesqlstr("p1.addtime");

        $_order = 'order by p1.id desc';
        $_select = "p1.*,p2.username,p2.recommender,p2.phone";

        $sql = "select SELECT from `jd_task_jd_list` as p1
   left join  `jd_users` as p2  on   p1.business_id=p2.id              
               SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);

        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            switch ($v['status']) {
                case 5:
                    $result['list'][$id]['status'] = '待审核';
                    break;
                case 6:
                    $result['list'][$id]['status'] = '已通过';
                    break;
                case 7:
                    $result['list'][$id]['status'] = '已拒绝';
                    break;
            }
        }

        $this->sendjsonmsg($result);
    }


    public function getpaylistactionExcel($date1 = "", $date2 = "", $username = "", $recommender = "")
    {
        $page = 1;
        $epage = 20000;
        if (empty($epage)) {
            $epage = 10;
        }
        $where = "where  p1.`status`=1 ";
        if ($date1) {
            $date1 = strtotime($date1);
            $where .= " AND  p1.addtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime($date2);
            $where .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username)) {
            $where .= " AND p1.account= '$username'";
        }
        if (!empty($recommender)) {
            $where .= " AND p2.recommender= '$recommender'";
        }

        $this->load->model('Jd_pay_model');


        $_order = 'order by p1.id desc';
        $_select = "p1.id,p2.username,p2.recommender,p1.addtime,p1.money,p1.money_maker,p1.account";
        $sql = "select SELECT from `jd_pay` as p1
                left join  `jd_users` as p2  on   p1.user_id=p2.id              
                             			   SQL  group  by   p1.id  ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);


        $this->load->model('Jd_pay_model');
        $result = $this->Jd_pay_model->get_server_list($_data);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
        }
        $str[] = 'ID';
        $str[] = '用户名';
        $str[] = '推荐人';
        $str[] = '创建时间';
        $str[] = '充值金额';
        $str[] = '转账姓名';
        $str[] = '转账账户';
        $this->excel_out($str, $result['list'], "充值完成记录");
    }


    /**
     * 审核商户的充值
     * @param $id
     */
    public function PayExamine()
    {
        $id = $this->input->post('id');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您不是财务无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');

        $a = $this->Jd_pay_model->approvepay($id);

        if (!$a) {
            $msg['code'] = 2;
            $msg['msg'] = "审核失败或者重复审核";
            $this->sendjsonmsg($msg);
        }
        $row['money'] = $a['money'];
        $row['user_id'] = $a['user_id'];
        $this->project = 3;
        $result = $this->moneyupdate($row, 1, $id);
        if ($result) {
            $this->sendjsonmsg();
        }
        if (!$a) {
            $msg['code'] = 0;
            $msg['msg'] = "审核成功";
            $this->sendjsonmsg($msg);
        }

    }

    /**
     * 拒绝充值
     */
    public function PayRefuse()
    {
        $id = $this->input->post('id');
        $remarks = $this->input->post('remarks');
        $this->project = 3;
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您不是财务无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');
        $a = $this->Jd_pay_model->PayRefuse($id, $remarks);
        if (!$a) {
            $msg['code'] = 2;
            $msg['msg'] = "状态更新失败";
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "拒绝完成";
        $this->sendjsonmsg($msg);
    }


    /**
     * 审核商户的退款
     * @param $id
     */
    public function refundExamine()
    {
        $id = $this->input->post('id');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');
        $this->load->model('Jd_task_jd_list_model');
        $row = $this->input->post();


        $id = $row['id'];
        $res = $this->db->select("id,status,business_id,real_price,gold")->from('task_jd_list')->where("`id`='$id'")->get()->result_array();
        $res = $res[0];
        if (!isset($row['gold']) || $row['gold'] != 'true') {
            $res['gold'] = 0;
        }
        if ($res && $res['status'] == 5) {
            $row['status'] = 6;
            //$row['real_price'] = 0;
            unset($row['id']);
            $this->Jd_task_jd_list_model->update("", 'id', $id, $row);
            // echo $this->db->last_query(); exit;
        } else {
            $msg['msg'] = "该任务不可申请退款";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }
        $row = array();
        $row['money'] = $res['real_price'];
        $row['user_id'] = intval($res['business_id']);
        $row['gold'] = $res['gold'];
        $row['remarks'] = '任务退款';
        $this->project = 3;
        $result = $this->moneyupdate($row, 6, $id);
        if (!$result || (isset($result['code']))) {
            $msg['code'] = 1;
            $msg['msg'] = "审核失败";
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "审核成功";
        $this->sendjsonmsg($msg);
    }

    /**
     * 拒绝退款
     */
    public function refundRefuse()
    {
        $id = $this->input->post('id');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_task_jd_list_model');
        $row = $this->input->post();
        $id = $row['id'];
        $res = $this->db->select("id,status,business_id,real_price")->from('task_jd_list')->where("`id`='$id'")->get()->result_array();
        $res = $res[0];
        if ($res && $res['status'] == 5) {
            $row['status'] = 2;
            unset($row['id']);
            $this->Jd_task_jd_list_model->update("", 'id', $id, $row);
            // echo $this->db->last_query(); exit;
        } else {
            $msg['msg'] = "任务状态异常";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "拒绝完成";
        $this->sendjsonmsg($msg);
    }


    /**
     * 审核站点提现
     * @param $id
     */
    public function cashExamine()
    {
        $id = $this->input->post('id');
        if ($this->user_id != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_pay_model');
        $this->load->model('Jd_web_month_model');
        $row = $this->input->post();
        $id = $row['id'];
        $res = $this->db->select("id,status,profit,webid")->from('jd_web_month')->where("`id`='$id'")->get()->result_array();

        $info = $res[0];
        $webid = $info['webid'];

        if ($info && $info['status'] == 1) {
            $row['status'] = 2;
            $row['cash'] = $info['profit'];
            unset($row['id']);
            $res = $this->Jd_web_month_model->update("", 'id', $id, $row);
        } else {
            $msg['msg'] = "不可申请提现";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }
        if (!$res) {
            $msg['msg'] = "审核失败";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }

        $webowon = $this->db->select("id")->from('jd_users')->where("`webid`=$webid AND `group`=1 ")->get()->result_array();
        $row = array();
        $row['money'] = $info['profit'];
        $row['user_id'] = $webowon[0]['id'];
        $row['remarks'] = '站点提现';
        $this->project = 3;
        $result = $this->moneyupdate($row, 8, $id);
        if (!$result) {
            $msg['code'] = 1;
            $msg['msg'] = "审核失败";
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "审核成功";
        $this->sendjsonmsg($msg);
    }

    /**
     * 拒绝提现
     */
    public function cashRefuse()
    {
        $id = $this->input->post('id');
        if ($this->user_id != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您无权进行审核";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_web_month_model');
        $row = $this->input->post();
        $id = $row['id'];
        $res = $this->db->select("id,status,profit,webid")->from('jd_web_month')->where("`id`='$id'")->get()->result_array();
        $res = $res[0];
        if ($res && $res['status'] == 1) {
            $row['status'] = 0;
            unset($row['id']);
            $this->Jd_web_month_model->update("", 'id', $id, $row);
            // echo $this->db->last_query(); exit;
        } else {
            $msg['msg'] = "状态异常拒绝提现";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "拒绝完成";
        $this->sendjsonmsg($msg);
    }


    /**
     *
     * 计算商户所有余额状态
     */
    public function totalbusiness()
    {
        $now = time();
        $yestodaydate = date("Y-m-d", strtotime("-1 day"));
        $yestoday = strtotime($yestodaydate); //昨天凌晨
        $this->load->model('Jd_task_jd_list_model');
        $row = $this->Jd_task_jd_list_model->totalbunissmoney($yestoday);
        $this->load->model('Jd_buniess_balance_model');
        $this->Jd_buniess_balance_model->addlog($row, $yestodaydate);
    }


    //销售情况页面
    public function Salelist()
    {
        $this->load->library('parser');
        $data['title'] = '销售列表';
        $this->address = '销售列表';


        $this->load->view('Customer/head', $data);
        $this->load->view('Customer/left');
        $this->load->view('Customer/Salelist');
    }


    /**
     * 获取销售列表
     */
    public function GetAllSaleList()
    {

        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $phone = $this->input->post('phone') ? $this->input->post('phone') : "";

        $date = $this->input->post('date') ? $this->input->post('date') : "";
        if (!$date) {
            $date = date('Y-m-d');
        }
        $month = date('Y-m-1', strtotime($date));
        $_sql = "where p1.`group`=6 ";
        if (!empty($username)) {
            $_sql .= " AND p1.username= '$username'";
        }
        if (!empty($phone)) {
            $_sql .= " AND p1.phone= '$phone'";
        }
        $_select = " p1.*,p2.extension_nub,p2.extension_nub_day,p2.extension";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_user_total` as p2  on   p1.id=p2.user_id              
                             			   SQL   ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $result = $this->Jd_users_model->get_server_list($_data);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['status'] = $v['status'] == 0 ? '禁用中' : '正常';
            $result['list'][$id]['link'] = $this->SetExtensionLink($v['id']);
        }

        //var_dump($result); exit;
        $this->sendjsonmsg($result);

    }


    //销售情况页面
    public function Salelog()
    {
        $this->load->library('parser');
        $data['title'] = '销售记录';
        $this->address = '销售列表';
        $this->load->view('Customer/head', $data);
        $this->load->view('Customer/left');
        $this->load->view('Customer/Saleloglist');
    }


    /**
     * 获取销售列表
     */
    public function GetSaleloglist()
    {

        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $date1 = $this->input->post('date1') ? $this->input->post('date1') : "";
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : "";

        $_sql = " where 1=1 ";
        if (!empty($username)) {
            $_sql .= " AND p2.username= '$username'";
        }

        if ($date1) {
            //$date1=strtotime(date('Y-m-d 00:00:00',strtotime($date1)));
            $_sql .= " AND p2.addtime>'$date1' ";
        }
        if ($date2) {
            // $date2=strtotime(date('Y-m-d 23:59:59',strtotime($date2)));
            $_sql .= " AND p2.addtime<'$date2' ";
        }


        $_select = "p2.*";
        $_order = " order by p2.id desc ";
        $sql = "select SELECT from 
                `jd_recommended_log` as p2      
                             			   SQL   ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_Recommended_log');
        $result = $this->Jd_Recommended_log->get_server_list($_data);
        //var_dump($result); exit;
        $this->sendjsonmsg($result);
    }

    public function SaleStatus()
    {

        $this->load->library('parser');


        $this->address = '销售情况';

        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/SaleStatus');
    }


    /**
     * 获取销售状况
     */
    public function GetSaleStatuslist()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $phone = $this->input->post('phone') ? $this->input->post('phone') : "";

        $date = $this->input->post('date') ? $this->input->post('date') : "";
        if (!$date) {
            $date = date('Y-m-d');
        }
        $month = date('Y-m-1', strtotime($date));
        $_sql = "where p1.`group`=6 ";
        if (!empty($username)) {
            $_sql .= " AND p1.username= '$username'";
        }
        if (!empty($phone)) {
            $_sql .= " AND p1.phone= '$phone'";
        }
        $_select = " p1.*, p2.task_nub,p2.extension_nub,p2.extension_nub_day,p2.extension";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_users` as p1
                left join  `jd_user_total` as p2  on   p1.id=p2.user_id              
                             			   SQL   ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_users_model');
        $result = $this->Jd_users_model->get_server_list($_data);

        $channellist = $this->getchannellist(1);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['channelname'] = $v['channel'] ? $channellist[$v['channel']] : "";
        }

        //var_dump($result); exit;
        $this->sendjsonmsg($result);


    }


    public function userControl()
    {
        $this->load->library('parser');

        $this->address = '用户管理';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $data['salerlist'] = $this->getsalerlist("id,username");
        $this->load->view('Customer/businesslist', $data);
    }


    /**
     * 手动调整用户资金
     */
    public function Manualpay()
    {
        $user_id = $this->input->post('user_id');
        $money = $this->input->post('money') ? $this->input->post('money') : 0;
        $gold = $this->input->post('gold') ? $this->input->post('gold') : 0;
        $remrk = $this->input->post('remrk') ? $this->input->post('remrk') : "";
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您不是财务无权资金改动";
            $this->sendjsonmsg($msg);
        }
        $row['user_id'] = $user_id;
        $row['money'] = $money;
        $row['gold'] = $gold;
        $row['remarks'] = $remrk;
        $r = $this->moneyupdate($row, 6, $this->user_id);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "资金改动失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }


    /**
     *  手动调整测试员资金
     */
    public function ManuaHunterMoney()
    {
        $user_id = $this->input->post('user_id');
        $money = $this->input->post('money');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "您不是财务无权资金改动";
            $this->sendjsonmsg($msg);
        }
        $row['user_id'] = $user_id;
        $row['money'] = $money;


        $this->db->trans_begin();
        $r = $this->moneyupdate($row, 6, $this->user_id);
        if (!$r) {
            $this->db->trans_rollback();
            $msg['code'] = 1;
            $msg['msg'] = "资金改动失败";
            $this->sendjsonmsg($msg);
        }
        if ($money > 0) {
            $hunterinfo = $this->getcuserinfo(1, $user_id);
            if ($hunterinfo['group'] == 3) {
                $this->load->model('Jd_hunter_total_day_model');
                $r = $this->Jd_hunter_total_day_model->addsendmoney($row);
            }
        }
        if (!$r) {
            $this->db->trans_rollback();
            $msg['code'] = 1;
            $msg['msg'] = "资金改动失败";
            $this->sendjsonmsg($msg);
        }
        $this->db->trans_commit();
        $this->sendjsonmsg();
    }

    /**
     * 为商户分配销售
     */
    public function distribution()
    {
        $user_id = $this->input->post('user_id');
        $salerid = $this->input->post('salerid');
        $this->load->model('Jd_users_model');
        $salername = $this->Jd_users_model->GetUserById($salerid, "username");
        $salername = $salername['username'];
        $row['user_id'] = $user_id;
        $row['salername'] = $salername;
        $row['recommender'] = $salername;
        $row['recommender_id'] = $salerid;
        $result = $salername = $this->Jd_users_model->updata_user($row);
        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '分配失败';
        $this->sendjsonmsg($msg);
    }


    /**
     * 获取用户佣金配置信息
     */
    public function getcommissionbyuser()
    {
        $user_id = $this->input->post('user_id');
        $this->load->model('Jd_users_model');
        $commissions = $this->Jd_users_model->GetUserById($user_id, "commission,commission2");
        $commission = $commissions['commission'];
        $commission2 = $commissions['commission2'];
        if (empty($commission)) {
            $commission = array(200, 8, 200, 2);
        } else {
            $commission = unserialize($commission);
        }
        if (empty($commission2)) {
            $commission2 = array(50, 3, 100, 1);
        } else {
            $commission2 = unserialize($commission2);
        }
        $commission3 = array_merge($commission, $commission2);

        $msg['code'] = 0;
        $msg['data'] = $commission3;
        $this->sendjsonmsg($msg);
    }

    /**
     * 获取佣金列表
     */
    public function getcommissionlist()
    {
        $commission[0] = $this->getcommissionconfig(1, 1, 1);
        $commission[1] = $this->getcommissionconfig(1, 1, 2);
        $commission[2] = $this->getcommissionconfig(1, 1, 3);
        $commission[3] = $this->getcommissionconfig(1, 1, 4);
        $list = [];
        for ($i = 0; $i < 8; $i++) {
            $row = [];
            foreach ($commission as $key => $vlaue) {
                $money = $vlaue['money'][$i] . "-" . $vlaue['money'][$i + 1];
                $gold = $vlaue['gold'][$i];
                $row[] = $money;
                $row[] = $gold;
            }
            $list[$i] = $row;
        }
        $msg['code'] = 0;
        $msg['list'] = $list;

        $this->sendjsonmsg($msg);

    }


    /**
     * 修改佣金配置
     */
    public function editcommission()
    {
        $index = $this->input->post('index') ? $this->input->post('index') : null;
        $value = $this->input->post('value') ? $this->input->post('value') : null;
        $key = $this->input->post('key') ? $this->input->post('key') : null;
        $key = intval(ceil($key / 2));
        $typelist = ['普通单佣金', '高留评单佣金', '多多进宝单佣金', '拼多多直播单佣金'];
        $titel = $typelist[$key - 1];
        $costlist = parent::getconfig("cost");
        $cost = $costlist[$key];
        $name = 'commission' . $key;
        $this->load->model('Jd_config_model');
        $res = $this->Jd_config_model->GetByname('commission' . $key, 'value,id', $this->web_id);
        $isnew = false;
        if (empty($res)) {
            $res = $this->Jd_config_model->GetByname('commission' . $key, 'value,id', 1);
            $isnew = true;
        }
        $id = $res['id'];
        $commission = $res['value'];
        $commission = unserialize($commission);
        $i = 0;
        foreach ($commission as $key => $v) {
            if ($i == $index) {
                if ($value < $cost) {
                    $msg['code'] = 1;
                    $msg['msg'] = "佣金不能小于" . $cost . "金币";
                    $this->sendjsonmsg($msg);
                }
                $commission[$key] = $value;
            }
            $i++;
        }
        $commission = serialize($commission);

        if (!$isnew) {
            $res = $this->Jd_config_model->updateinfo($id, $commission);
        } else {
            $row = array();
            $row['name'] = $name;
            $row['titel'] = trim($titel);
            $row['value'] = $commission;
            $row['remark'] = $commission;
            $res = $this->Jd_config_model->addinfo($row);
        }
        if ($res) {//重置缓存
            $MYredis = $this->MyRedis();
            $key = "xinquanzhongconfig";
            $key = $key . "|" . $this->web_id;
            $MYredis->hSet($key, $name, $commission);
            $ttl = $MYredis->ttl($key);
            if ($ttl == -1) {
                $MYredis->expire($key, 15 * 60);
            }
            $msg['code'] = 0;
            $msg['msg'] = "修改成功";
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 1;
        $msg['msg'] = "修改失败";
        $this->sendjsonmsg($msg);
    }

    /**
     * 设置用户佣金信息
     */
    public function setcommission()
    {
        $user_id = $this->input->post('user_id');
        $xiaoyu1000 = $this->input->post('jdvalue1') ? $this->input->post('jdvalue1') : 200;
        $xiaoyu5000 = $this->input->post('jdvalue2') ? $this->input->post('jdvalue2') : 100;
        $xiaoyu10000 = $this->input->post('jdvalue3') ? $this->input->post('jdvalue3') : 100;
        $dayu10000 = $this->input->post('jdvalue4') ? $this->input->post('jdvalue4') : 10;


        $value1 = $this->input->post('value1') ? $this->input->post('value1') : 50;
        $value2 = $this->input->post('value2') ? $this->input->post('value2') : 50;
        $value3 = $this->input->post('value3') ? $this->input->post('value3') : 100;
        $value4 = $this->input->post('value4') ? $this->input->post('value4') : 10;

        $commission[] = $xiaoyu1000;
        $commission[] = $xiaoyu5000;
        $commission[] = $xiaoyu10000;
        $commission[] = $dayu10000;

        $commission2[] = $value1;
        $commission2[] = $value2;
        $commission2[] = $value3;
        $commission2[] = $value4;

        $commission = serialize($commission);
        $commission2 = serialize($commission2);
        $row['user_id'] = $user_id;
        $row['commission'] = $commission;
        $row['commission2'] = $commission2;
        $this->load->model('Jd_users_model');
        $result = $salername = $this->Jd_users_model->updata_user($row);
        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '设置佣金失败';
        $this->sendjsonmsg($msg);
    }

    /**
     * 禁止或者启用用户
     */
    public function stopuser()
    {
        $user_id = $this->input->post('user_id');
        $this->load->model('Jd_users_model');
        $status = $this->Jd_users_model->GetUserById($user_id, "status");
        $row['user_id'] = $user_id;
        $row['status'] = abs(1 - $status['status']);
        $result = $salername = $this->Jd_users_model->updata_user($row);
        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '修改状态成功';
        $this->sendjsonmsg($msg);
    }


    /**
     * 设置或者取消用户的VIP
     */
    public function setvip()
    {
        $user_id = $this->input->post('user_id');
        $this->load->model('Jd_users_model');
        $status = $this->Jd_users_model->GetUserById($user_id, "VIP");
        $row['user_id'] = $user_id;
        $row['VIP'] = abs(1 - $status['VIP']);
        $result = $salername = $this->Jd_users_model->updata_user($row);
        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '修改VIP状态成功';
        $this->sendjsonmsg($msg);
    }


    public function relodjdtask($id)
    {
        $this->address = '修改任务';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->model('Jd_task_jd_model');
        $row = $this->Jd_task_jd_model->getonebyid($id);
        $str = explode("/", $row['picurl']);
        if (isset($str[1]) && $str[1] == 'pic') {
            $row['picurl'] = base_url() . "public/uploads" . $row['picurl'];
        }
        $this->load->view('Customer/relodjdtask', $row);
    }


    /**
     * 编辑任务
     */
    public function EditTask()
    {
        if (empty($row)) {
            $row = $this->input->post();
        }
        $this->load->model('Jd_task_jd_model');
        if (!empty($row['pic'])) {
            $pic = $this->movepic($row['pic']);
            if (!$pic) {
                $msg['code'] = 1;
                $msg['msg'] = '图片上传失败';
                $this->sendjsonmsg($msg);
            }
            $newrow = array();
            $newrow['user_id'] = $this->user_id;
            $newrow['address'] = $pic['path'];
            $newrow['url'] = $pic['url'];
            $newrow['addtime'] = time();
            $this->load->model('Jd_pic_model');
            $result = $this->Jd_pic_model->addpic($newrow);

            if (!$result) {
                $msg['code'] = 1;
                $msg['msg'] = '图片上传失败';
                $this->sendjsonmsg($msg);
            }
            $row['pic'] = $result;
            $row['picurl'] = $pic['url'];
        }
        if ($row['releasetime']) {
            $row['releasetime'] = strtotime($row['releasetime']);
        }


        foreach ($row as $id => $v) {
            if (empty($v) && $id != "coupon" && $id != "remarks" && $id != "pic" && $id != "releasetime") {
                $msg['code'] = 1;
                $msg['msg'] = '缺少参数';
                $this->sendjsonmsg($msg);
            }
        }
        $this->load->model('Jd_task_jd_model');
        //$result=  $this->Jd_task_jd_model->getonebyid( $row['id']);
        if (isset($row['number'])) {
            unset($row['number']);
        }
        if (isset($row['pay_price'])) {
            unset($row['pay_price']);
        }
        if (isset($row['each_single'])) {
            unset($row['each_single']);
        }
        $row['id'] = intval($row['id']);
        $id = $row['id'];
        $result = $this->Jd_task_jd_model->taskupdate($row);
        unset($row['pic']);
        unset($row['releasetime']);
        if ($result) {
            $this->load->model('Jd_task_jd_list_model');
            $res = $this->db->select("1")->from('jd_task_jd_list')->where("`taskid`=$id")->get()->result_array();
            if ($res) {
                $result = $this->Jd_task_jd_list_model->taskupdate($row);
                if ($result) {
                    $res = $this->db->select("1")->from('jd_task_jd_list_pool')->where("`taskid`=$id")->get()->result_array();
                    if ($res) {
                        $this->load->model('Jd_task_jd_list_pool_model');
                        $this->Jd_task_jd_list_pool_model->taskupdate($row);
                    }
                }
            }
            if ($result) {
                $this->sendjsonmsg();
            }
        }
        $msg['code'] = 1;
        $msg['msg'] = '修改失败';
        $this->sendjsonmsg($msg);

    }


    /**
     * 编辑子任务
     */
    public function EditTaskchild()
    {
        if (empty($row)) {
            $row = $this->input->post();
        }
        $id = $row['id'];
        $this->load->model('Jd_task_jd_list_model');
        $res = $this->db->select("1")->from('jd_task_jd_list')->where("`id`=$id")->get()->result_array();


        if ($res) {
            $row['daifa_e'] = 0;
            $result = $this->Jd_task_jd_list_model->taskupdate($row, "id");
        }
        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '快递单号修改失败';
        $this->sendjsonmsg($msg);

    }


    /**
     * 编辑任务的评论
     */
    public function editcomment()
    {
        if (empty($row)) {
            $row = $this->input->post();
        }
        $id = $row['id'];
        $this->load->model('Jd_pic_model');
        unset($row['id']);

        $result = $this->Jd_pic_model->textupdate($id, $row);

        if ($result) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = '任务评论修改失败';
        $this->sendjsonmsg($msg);

    }


    /**
     * 手动增加用户
     */
    public function adduser()
    {
        if ($this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "只有管理员可以增加用户";
            $this->sendjsonmsg($msg);
        }
        $username = $this->input->post('username');
        $password = $this->input->post('password') ? $this->input->post('password') : "123456";
        $phone = $this->input->post('phone');
        $team = $this->input->post('team');
        $group = $this->input->post('group');
        $channel = $this->input->post('channel');
        $rate = $this->input->post('rate');
        $webid = $this->input->post('webid') ? $this->input->post('webid') : $this->web_id;
        $commission = $this->input->post('commission');
        $row['username'] = $username;
        $row['password'] = $password;
        if ($phone) {
            $row['phone'] = $phone;
        }
        if ($group) {
            $row['group'] = $group;
        }
        if ($team) {
            $row['team'] = $team;
        }
        if ($channel) {
            $row['channel'] = $channel;
        }
        if ($rate) {
            $row['rate'] = $rate;
        }
        if ($webid) {
            $row['webid'] = $webid;
        }
        if ($commission) {
            $row['commission'] = $commission;
        }
        $row['regtime'] = time();
        foreach ($row as $id => $v) {
            if ($v == null) {
                $msg['code'] = 1;
                $msg['msg'] = "缺少参数";
                $this->sendjsonmsg($msg);
            }
        }
        $this->load->model('Jd_users_model');

        $result = $this->Jd_users_model->GetUserByName($row['username'], "1");
        if (!empty($result)) {
            $msg['code'] = 1;
            $msg['msg'] = "用户名已经存在";
            $this->sendjsonmsg($msg);
        }

        $result = $this->Jd_users_model->GetUserByPhone($row['phone'], "1");
        if (!empty($result)) {
            $msg['code'] = 1;
            $msg['msg'] = "手机号已经存在";
            $this->sendjsonmsg($msg);
        }


        $status = $this->Jd_users_model->adduser($row);
        if ($status) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = "添加失败";
        $this->sendjsonmsg($msg);
    }


    /**
     * 编辑用户信息
     */
    public function edituser()
    {
        if ($this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "只有管理员可以修改用户";
            $this->sendjsonmsg($msg);
        }
        $user_id = $this->input->post('user_id');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $phone = $this->input->post('phone');
        $group = $this->input->post('group');
        $channel = $this->input->post('channel');
        $team = $this->input->post('team');
        $rate = $this->input->post('rate');
        $webid = $this->input->post('webid');
        $commission = $this->input->post('commission');
        $row['user_id'] = $user_id;
        $row['username'] = $username;
        if ($password) {
            $row['password'] = $password;
        }
        if ($phone) {
            $row['phone'] = $phone;
        }
        if ($group) {
            $row['group'] = $group;
        }
        if ($team) {
            $row['team'] = $team;
        }
        if ($channel) {
            $row['channel'] = $channel;
        }
        if ($rate) {
            $row['rate'] = $rate;
        }
        if ($webid) {
            $row['webid'] = $webid;
        }
        if ($commission) {
            $row['commission'] = $commission;
        }

        $this->load->model('Jd_users_model');
        $status = $this->Jd_users_model->updata_user($row);
        if ($status) {
            $this->sendjsonmsg();
        }
        $msg['code'] = 1;
        $msg['msg'] = "修改失败";
        $this->sendjsonmsg($msg);

    }


    //测试员管理页面
    public function CheckTheButton()
    {
        $this->load->library('parser');

        $this->address = '测试员管理';


        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/jd_CheckTheButton');
    }


    //账户管理页面
    public function accountManagement()
    {
        $this->load->library('parser');
        $data['title'] = '用户管理';
        $this->address = '用户管理';

        $this->load->view('Customer/head', $data);
        $this->load->view('Customer/left');
        $data['grouplist'] = $this->getgrouplist();
        unset($data['grouplist'][0]);
        $data['teamlist'] = $this->getteamlist();
        $data['channellist'] = $this->getchannellist();
        $this->load->view('Customer/userControl', $data);
    }

    /**
     *
     * 获取销售列表
     * @param string $select
     * @param bool $getall 是否获取所有分站的销售
     * @return mixed
     */
    public function getsalerlist()
    {
        if ($this->input->post('select')) {
            $select = $this->input->post('select');
        }
        $this->load->model('Jd_users_model');
        //$this->web_id=1;
        if ($this->web_id != 1) {
            $row = $this->Jd_users_model->getuserbygroup(6, $select);
        } else {
            $sql = 'select * from jd_users where `group`=6';
            $row = $this->Jd_users_model->GetBySql($sql);
        }
        if ($this->input->post('select')) {
            $msg['list'] = $row;
            $this->sendjsonmsg($msg);
        }
        return $row;
    }

    public function daylist()
    {
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/daylist');
    }

    public function getdaylist()
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $getexcel = $this->input->post('getexcel');
        if (empty($epage)) {
            $epage = 10;
        }
        $this->load->model('Jd_day_count_model');
        $time = $this->input->post('time') ? $this->input->post('time') : "";
        $where = "  where 1=1   ";
        if (!empty($time)) {
            $time = explode(" - ", $time);
            if ($time[0] == $time[1]) {
                $time = $time[0];
                $where .= " AND  p1.date= '$time'";
            } else {
                $where .= " AND  p1.date  between '$time[0]' and  '$time[1]'";
            }
        }
        $where .= $this->getsqlstrbyrow(['webid']);

        $_select = " p1.*";
        $_order = " order by p1.id  desc ";
        $sql = "select SELECT from `jd_day_count` as p1       
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);
        $a = $this->Jd_day_count_model->get_server_list($_data);

        if ($getexcel) {
            $str['date'] = ['日期', 20];
            $str['regnum'] = ['注册人数'];
            $str['pay'] = ['充值金额'];
            $str['pay_user'] = ['充值人数'];
            $str['task_money'] = ['任务本金'];
            $str['task_gold'] = ['消耗佣金）'];
            $str['back_money'] = ['对账返额'];
            $str['task_num'] = ['发布单量'];
            $str['balance'] = ['余额'];
            $str['balance_gold'] = ['剩余佣金'];
            $this->excel_out2($str, $a['list'], "1");
        }
        $this->sendjsonmsg($a);
    }


    public function piclist()
    {
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/piclist');
    }

    public function yongjin()
    {
        $this->load->view('Customer/head');
        $this->load->view('Customer/head2');
        $this->load->view('Customer/left');
        $this->load->view('Customer/yongjin');
    }


    public function banner()
    {
        $this->address = '轮播图管理';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/banner');
    }

    public function editbanner($id)
    {
        $this->address = '编辑图片';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->model('Jd_banner_model');
        $lits = $this->Jd_banner_model->getonebyid($id);
        $this->load->view('Customer/editbanner', $lits);
    }


    public function getpiclist()
    {


        $this->load->model('Jd_banner_model');
        $lits = $this->Jd_banner_model->getlist();
        foreach ($lits as $id => $v) {
            $v['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            // $v['url']=base_url() . "public/uploads/temporary" . $v['url'];
            $lits[$id] = $v;
        }

        $msg['code'] = 0;
        $msg['list'] = $lits;
        $msg['count'] = count($lits);

        $this->sendjsonmsg($msg);


    }

    public function addpic()
    {
        if (empty($row)) {
            $row = $this->input->post();
        }
        foreach ($row as $id => $v) {
            $row[$id] = trim($v);
        }

        if (!$row['url']) {
            $msg['code'] = 1;
            $msg['msg'] = "缺少图片";
            $this->sendjsonmsg($msg);
        }

        $this->load->model('Jd_banner_model');
        $r = $this->Jd_banner_model->addpic($row);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "添加失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    public function editepic()
    {
        if (empty($row)) {
            $row = $this->input->post();
        }
        foreach ($row as $id => $v) {
            $row[$id] = trim($v);
        }
        $this->load->model('Jd_banner_model');
        $id = $row['id'];

        unset($row['id']);
        $r = $this->Jd_banner_model->update('banner', "id", $id, $row);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "修改失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    public function delpic()
    {
        $id = $this->input->post('id');
        $this->load->model('Jd_banner_model');
        $r = $this->Jd_banner_model->delarticle($id);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "删除失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    function eidteruppic()
    {


        // $r= ini_get('upload_max_filesize');


        require_once(FCPATH . 'application/libraries/Uploader.php');

        //上传配置
        $config = array(
            "savePath" => "upload/",             //存储文件夹
            "maxSize" => 500000,                   //允许的文件最大尺寸，单位KB
            "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".avi", ".wma", ".rmvb", ".mp4", ".flv", ".3gp")  //允许的文件格式
        );


        $filetype = $_FILES['upfile']['type'];

        /*  $type=explode("/",$type);

          $filetype=$type[1];

          if($filetype=="octet-stream"){
              $type=explode(".",$_FILES['upfile']['name']);
              $filetype=$type[1];
          }*/


        /*  .AVI, .wma, .rmvb,.rm, .flash,.mp4,.mid, 3GP*/
        //上传文件目录
        $Path = "upload/";
        $Path = UPLOADS . "/temporary/"; //上传文件的存放路径
        //背景保存在临时目录中
        $config["savePath"] = $Path;
        $up = new Uploader("upfile", $config);

        @$type = $_REQUEST['type'];
        @$callback = $_GET['callback'];

        $info = $up->getFileInfo();
        $info['url'] = base_url() . "public/uploads/temporary/" . date("Ymd") . "/" . $info['name'];

        // $info['url']="../public/uploads/temporary/".date("Ymd")."/".$info['name'];
        $info['code'] = 0;
        //  $info['name']="/".date("Ymd")."/". $info['name'];
        $info['type'] = $filetype;

        /**
         * 返回数据
         */
        if ($callback) {
            echo '<script>' . $callback . '(' . json_encode($info) . ')</script>';
        } else {
            echo json_encode($info);
        }

    }

    function getconfiglist()
    {
        $this->load->model('Jd_config_model');
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');

        $this->load->model('Jd_day_count_model');
        $where = "  where 1=1   ";
        $where .= $this->getsqlstrbyrow(['webid', 'name', 'titel']);
        $_select = " p1.*";
        $_order = " order by p1.id  desc ";
        $sql = "select SELECT from `jd_config` as p1       
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);
        $lits = $this->Jd_config_model->get_server_list($_data);
        foreach ($lits['list'] as $id => $v) {

            //$lits['list'][$id]['value2'] =strlen($v['value']);

            $lits['list'][$id]['value2'] = json_encode(unserialize($v['value']));
            $lits['list'][$id]['remark'] = json_encode(unserialize($v['remark']));
        }
        $this->sendjsonmsg($lits);

    }


    public function addconfig()
    {

        $this->load->view('Customer/head2');
        $this->load->view('Customer/addconfig');
    }

    public function editeconfig()
    {
        $this->load->view('Customer/head2');
        $this->load->view('Customer/editeconfig');
    }

    public function addconfigdo()
    {
        $row = $this->input->post();
        $this->load->model('Jd_config_model');
        $configvalue = array();
        $remark = array();
        if (is_array($row['value'])) {
            foreach ($row['value'] as $id => $value) {
                if (!isset($value['key']) || !isset($value['value'])) {
                    $msg['code'] = 1;
                    $msg['msg'] = "缺少参数";
                    $this->sendjsonmsg($msg);
                }
                $configvalue[$value['key']] = $value['value'];
                $remark[] = $value['remark'];
            }
        } else {
            $key = $row['key'];
            $value = $row['value'];
            $remark = $row['remark'];

            foreach ($key as $id => $v) {
                if (!isset($value[$id]) || !isset($remark[$id])) {
                    $msg['code'] = 1;
                    $msg['msg'] = "缺少参数";
                    $this->sendjsonmsg($msg);
                }
                $configvalue[$v] = $value[$id];
            }
        }

        //var_dump($configvalue); exit;

        $addrow = array();
        $addrow['name'] = $row['name'];
        $addrow['titel'] = $row['titel'];
        $addrow['value'] = serialize($configvalue);
        $addrow['remark'] = serialize($remark);


        $r = $this->Jd_config_model->addinfo($addrow);

        if ($r) {
            $msg['code'] = 0;
            $msg['msg'] = "添加成功";
            $this->sendjsonmsg($msg);
        }

        $msg['code'] = 1;
        $msg['msg'] = "添加失败";
        $this->sendjsonmsg($msg);

    }

    public function delconfig()
    {
        $id = $this->input->post('id');
        $this->load->model('Jd_config_model');
        $r = $this->Jd_banner_model->delarticle($id);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "删除失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    public function editeconfigdo()
    {
        $row = $this->input->post();
        $this->load->model('Jd_config_model');
        $configvalue = array();
        $remark = array();
        if (is_array($row['value'])) {
            foreach ($row['value'] as $id => $value) {

                // var_dump($value);
                if (!isset($value['key']) || !isset($value['value'])) {
                    $msg['code'] = 1;
                    $msg['msg'] = "缺少参数";
                    $this->sendjsonmsg($msg);
                }
                $configvalue[$value['key']] = $value['value'];
            }
            // var_dump($configvalue); exit;
        } else {
            $key = $row['key'];
            $value = $row['value'];
            $remark = $row['remark'];
            foreach ($key as $id => $v) {
                if (!isset($value[$id]) || !isset($remark[$id])) {
                    $msg['code'] = 1;
                    $msg['msg'] = "缺少参数";
                    $this->sendjsonmsg($msg);
                }
                $configvalue[$v] = $value[$id];
            }
        }

        //var_dump($configvalue); exit;
        $configvalue = serialize($configvalue);


        $r = $this->Jd_config_model->updateinfo($row['id'], $configvalue);
        if ($r) {
            $msg['code'] = 0;
            $msg['msg'] = "修改成功";
            $this->sendjsonmsg($msg);
        }

        $msg['code'] = 1;
        $msg['msg'] = "修改失败";
        $this->sendjsonmsg($msg);

    }


    /**
     * 导出订单信息
     * @param $page
     * @param $eapge
     * @param $orderid
     * @param $date1
     * @param $date2
     * @param $shop_name
     */
    public function pddtaskhexcel($taskid)
    {

        $page = 1;
        $epage = 20000;
        $where = "where taskid= $taskid";
        $order['id'] = "DESC";
        $_select = " p1.id,p1.addtime,p1.update,p1.orderid,p1.shop_name,p1.awz,p1.sku,p1.price,p1.real_price,p1.taskid,p1.daifa";
        $_order = " order by p1.id desc ";
        $sql = "select SELECT from `jd_task_jd_list` as p1
               SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $a = $this->Jd_task_jd_model->get_server_list($_data);

        //echo $this->db->last_query();die;
        //  $a=  $this->Jd_task_jd_list_model->pageData($where,"*",$page,$epage,$order);
        $a['epage'] = $epage;
        $a['page'] = $page;
        $isdaifa = 0;
        foreach ($a['list'] as $id => $v) {
            $a['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);

            if (!empty($v['update'])) {
                $a['list'][$id]['update'] = date('Y-m-d H:i:s', $v['update']);
            } else {
                $a['list'][$id]['update'] = "";
            }
            $a['list'][$id]['orderid'] = "";
            $a['list'][$id]['awz'] = "";
            $isdaifa = $v['daifa'];
            unset($a['list'][$id]['daifa']);
        }
        $str[] = 'ID';
        $str[] = '加入时间';
        $str[] = '更新时间';
        $str[] = '订单号';
        $str[] = '店铺名';
        $str[] = 'AWZ';
        $str[] = 'SKU';
        $str[] = '录入价格';
        $str[] = '实际付款';
        $str[] = '任务ID';
        if ($isdaifa) {
            $str[] = '地址';
        }
        $this->excel_out($str, $a['list'], "测试员订单记录");
    }

    public function tasklist()
    {
        $this->address = '拼多多任务列表';
        $this->load->view('Customer/head');
        $this->load->view('Customer/left');
        $this->load->view('Customer/tasklist');
    }

    public function gettasklist($type = 1, $show = 0, $issrot = false)
    {
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $status = $this->input->post('status');
        $id = $this->input->post('id');
        $username = $this->input->post('username') ? $this->input->post('username') : "";
        $shop_name = $this->input->post('shop_name') ? $this->input->post('shop_name') : "";
        $keyword = $this->input->post('keyword') ? $this->input->post('keyword') : "";
        $date1 = $this->input->post('date1') ? $this->input->post('date1') : "";
        $date2 = $this->input->post('date2') ? $this->input->post('date2') : "";


        $time = time();
        $_sql = "where   (p1.releasetime<$time or  p1.releasetime is null )  AND  p1.type=$type";

        if ($show) {
            $_sql = "where  p1.type=$type";
        }


        if ($status != "") {
            $_sql .= " AND p1.status=$status ";
        } else {
            $_sql .= " AND p1.status in (0,1,4) ";
        }


        if ($date1) {
            $date1 = strtotime(date('Y-m-d 00:00:00', strtotime($date1)));
            $_sql .= " AND p1.addtime>$date1 ";
        }
        if ($date2) {
            $date2 = strtotime(date('Y-m-d 23:59:59', strtotime($date2)));
            $_sql .= " AND p1.addtime<$date2 ";
        }
        if (!empty($username)) {
            $_sql .= " AND p2.username= '$username'";
        }
        if (!empty($shop_name)) {
            $_sql .= " AND p1.shop_name= '$shop_name'";
        }
        if (!empty($key_word)) {
            $_sql .= " AND p1.keyword= '$keyword'";
        }

        if (!empty($id)) {
            $_sql .= " AND p1.id= '$id'";
        }
        $_select = " p1.*,p2.username,p2.salername";
        $_order = " order by p1.id desc ";


        $sql = "select SELECT from `jd_task_jd` as p1             
            left join jd_users as p2 on p2.id=p1.business_id 
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $_sql,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);

        $this->load->model('Jd_task_jd_model');
        $result = $this->Jd_task_jd_model->get_server_list($_data);
        foreach ($result['list'] as $id => $v) {
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            $result['list'][$id]['money'] = round($v['pay_price'] * $v['number'] * $v['each_single'], 2);
            $result['list'][$id]['number'] = $v['finish_nub'] . "/" . $v['number'];
            $result['list'][$id]['Surplus'] = $v['number'] - $v['finish_nub'];
            $result['list'][$id]['type_hname'] = $v['type_h'] == 1 ? "普通单" : "高留评";


            if ($v['releasetime'] > time()) {
                $result['list'][$id]['status'] = 0;
            }
            $result['list'][$id]['releasetime'] = $v['releasetime'] ? date('Y-m-d H:i:s', $v['releasetime']) : "";
            switch ($v['pay_type']) {
                case 1:
                    $result['list'][$id]['pay_type'] = '全部开团';
                    break;
                case 2:
                    $result['list'][$id]['pay_type'] = '单独购买';
                    break;
                case 3:
                    $result['list'][$id]['pay_type'] = '优先参团';
                    break;
            }
            // $a['list'][$id]['status']=$v['status']==0?'待审核':'通过审核';
        }
        $this->sendjsonmsg($result);

    }

    public function changeStatus($id = "", $status = "")
    {
        if (!$id) {
            $id = $this->input->post('id');
            $id = intval($id);
        }
        if (!$status) {
            $status = $this->input->post('status');
            $status = intval($status);
        }
        $this->load->model('Jd_task_jd_model');
        if ($status != 1) {
            $this->load->model('Jd_task_jd_model');
            $result = $this->Jd_task_jd_model->UpdateStatus($id, $status);
        } else {
            $row = [];
            $row['id'] = $id;
            $row['releasetime'] = time();
            // $result = $this->Jd_task_jd_model->taskupdate($row);
        }
        $row = $this->Jd_task_jd_model->getonebyid($id);
        $allmoney = $row['pay_price'] * $row['each_single'] * $row['number'];
        $allgold = $row['gold'];

        $new["user_id"] = $row['business_id'];
        if ($status == 4) {
            $new['frozenmoney'] = -abs($allmoney);
            $new['frozengold'] = -abs($allgold);
        }
        if ($status == 0) {
            $new['frozenmoney'] = abs($allmoney);
            $new['frozengold'] = abs($allgold);
        }
        $result = $this->frozenmoney($new);
        $msg['code'] = 1;
        $msg['msg'] = '设置失败';
        if ($result) {
            $msg['code'] = 0;
            $msg['msg'] = '设置成功';
        }
        $this->sendjsonmsg($msg);
    }


    /**
     * 销量任务完成和废除
     * @param string $id
     * @param string $status
     */
    public function changeSalesStatus($id = "", $status = "")
    {
        if (!$id) {
            $id = $this->input->post('id');
            $id = intval($id);
        }
        if (!$status) {
            $status = $this->input->post('status');
            $status = intval($status);
        }


        $this->load->model('jd_changesals_model');
        $info = $this->jd_changesals_model->getonebyid($id);

        if ($info['status'] != 0) {
            $msg['code'] = 1;
            $msg['msg'] = '状态错误';
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 1;
        $msg['msg'] = '设置失败';
        $result = $this->jd_changesals_model->UpdateStatus($id, $status);
        if (!$result) {
            $this->sendjsonmsg($msg);
        }
        if ($status == 4) {
            $new = array();
            $new["money"] = -$info['money'];
            $new["gold"] = -$info['gold'];
            $new["user_id"] = $info['user_id'];
            $new["remarks"] = "改销量任务回退";
            $new["log_id"] = $id;
            $result = $this->moneyupdate($new, 6);
        }
        if ($result) {
            $msg['code'] = 0;
            $msg['msg'] = '设置成功';
        }
        $this->sendjsonmsg($msg);
    }

    public function getconfig($name)
    {
        $res = parent::getconfig($name); // TODO: Change the autogenerated stub

        $msg['list'] = $res;
        $this->sendjsonmsg($msg);

    }


    /**
     * 提交快递订单信息
     * @throws PHPExcel_Exception
     * @throws PHPExcel_Reader_Exception
     */
    public function updateexpressid()
    {
        $row = $this->setexcelToArray();
        $msg['code'] = 1;
        $this->load->model('Jd_task_jd_list_model');
        foreach ($row as $id => $v) {
            if (!$v['A'] || !$v['B'] || !$v['C']) {
                $msg['msg'] = "缺少参数";
                continue;
            }
            $orderid = $v['A'];
            $express = $v['B'];
            $expressorderid = $v['C'];
            $row = array();
            $row['orderid'] = $orderid;
            $row['express'] = $express;
            $row['expressorderid'] = $expressorderid;
            $row['daifa_e'] = 0;
            $res = $this->db->select("daifa,id")->from('jd_task_jd_list')->where("`orderid`='$orderid'")->get()->result_array();
            if (!$res) {
                continue;
            }
            $res = $res[0];
            if ($res && $res['daifa'] == 1) {
                $row['id'] = $res['id'];
                unset($row['orderid']);
                $result = $this->Jd_task_jd_list_model->taskupdate($row, 'id');
                // var_dump($result); exit;
            }


        }
        $msg['msg'] = "更新完成";
        $msg['code'] = 0;
        $this->sendjsonmsg($msg);
    }


    private function list_dir($dir)
    {

        $result = array();

        if (is_dir($dir)) {

            $file_dir = scandir($dir);

            foreach ($file_dir as $file) {

                if ($file == '.' || $file == '..') {

                    continue;

                } elseif (is_dir($dir . $file)) {

                    $result = array_merge($result, $this->list_dir($dir . $file . '/'));

                } else {

                    array_push($result, $dir . $file);

                }

            }

        }

        return $result;

    }


    public function getshowpiczip($id)
    {
        $this->load->model('Jd_task_jd_model');
        $row = $this->Jd_task_jd_model->getonebyid($id);


        if ($row['releasetime']) {
            $date = date("Y-m-d", $row['releasetime']);
        } else {
            $date = date("Y-m-d", $row['addtime']);
        }
        if (!$row['showpic']) {
            $msg['code'] = 1;
            $msg['msg'] = "该任务没有晒图";
            $this->sendjsonmsg($msg);
        }
        $where['taskid'] = $id;
        $result = $this->db->select('*')->from('pic')->where($where)->get()->result_array();

        $path = $result[1]['address'];

        $team = $row['team'];
        if (!$team) {
            $teamstr = "无团队";
        } else {
            $teamlist = parent::getteamlist('team');
            $team = explode(",", $team);
            $teamstr = array();
            foreach ($team as $id => $v) {
                $teamstr[] = $teamlist[$v];
            }
            $teamstr = implode("-", $teamstr);
        }
        $path = explode("/", $path);
        unset($path[count($path) - 1]);

        if ($path[count($path) - 2] == 'new') {
            $path[count($path) - 2] = 'old';
            $path[count($path) - 1] = 'yswj.zip';
            ob_start();
            $flie = implode("/", $path);
            $filename = $date . "-" . $row['shop_name'] . "-" . $row['id'] . "-" . $row['goods_name'] . "-" . $teamstr . ".zip"; //最终生成的文件名（含路径）
            $size = readfile($flie);
            header("Content-type:  application/octet-stream ");
            header("Accept-Ranges:  bytes ");
            header("Content-Disposition:  attachment;  filename= {$filename}");
            header("Accept-Length: " . $size);
            exit;
        }
        $falinpath = implode("/", $path) . "/";
        $datalist = $this->list_dir($falinpath);
        $filename = $falinpath . "./" . $date . "-" . $row['shop_name'] . "-" . $row['id'] . "-" . $row['goods_name'] . "-" . $teamstr . ".zip"; //最终生成的文件名（含路径）
        if (!file_exists($filename)) {
            $zip = new ZipArchive();//使用本类，linux需开启zlib，windows需取消php_zip.dll前的注释
            if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
                exit('无法打开文件，或者文件创建失败');
            }
            foreach ($datalist as $val) {
                if (file_exists($val)) {
                    $zip->addFile($val, basename($val));//第二个参数是放在压缩包中的文件名称，如果文件可能会有重复，就需要注意一下
                }
            }
            $zip->close();//关闭
        }
        if (!file_exists($filename)) {
            exit("无法找到文件"); //即使创建，仍有可能失败。。。
        }
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header('Content-disposition: attachment; filename=' . basename($filename)); //文件名
        header("Content-Type: application/zip"); //zip格式的
        header("Content-Transfer-Encoding: binary"); //告诉浏览器，这是二进制文件
        header('Content-Length: ' . filesize($filename)); //告诉浏览器，文件大小
        @readfile($filename);
    }

    public function gettextpath($id)
    {
        $this->load->model('Jd_task_jd_model');
        $row = $this->Jd_task_jd_model->getonebyid($id);


        if ($row['releasetime']) {
            $date = date("Y-m-d", $row['releasetime']);
        } else {
            $date = date("Y-m-d", $row['addtime']);
        }
        if (!$row['textpath']) {
            $msg['code'] = 1;
            $msg['msg'] = "该任务没有指定评论";
            $this->sendjsonmsg($msg);
        }
        $path = $row['textpath'];
        $team = $row['team'];
        if (!$team) {
            $teamstr = "无团队";
        } else {
            $teamlist = parent::getteamlist('team');
            $team = explode(",", $team);
            $teamstr = array();
            foreach ($team as $id => $v) {
                $teamstr[] = $teamlist[$v];
            }
            $teamstr = implode("-", $teamstr);
        }
        ob_start();
        $filename = $date . "-" . $row['shop_name'] . "-" . $row['id'] . "-" . $row['goods_name'] . "-" . $teamstr . ".txt"; //最终生成的文件名（含路径）
        $size = readfile($path);
        header("Content-type:  application/octet-stream ");
        header("Accept-Ranges:  bytes ");
        header("Content-Disposition:  attachment;  filename= {$filename}");
        header("Accept-Length: " . $size);
        exit;
    }


    public function getWebMonthlist()
    {
        $this->load->model('Jd_web_month_model');
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $where = "  where 1=1   ";
        $where .= $this->getsqlstrbyrow(['webid']);

        $where .= $this->gettimesqlstr();
        if (!$_POST['webid'] && $this->web_id == 1) {
            $_POST['webid'] = "全部";//搜全部站点
        }

        $_select = " p1.*";
        $_order = " order by p1.id  desc ";
        $sql = "select SELECT from `jd_web_month` as p1       
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);


        $lits = $this->Jd_web_month_model->get_server_list($_data);


        foreach ($lits['list'] as $id => $v) {
        }

        $this->sendjsonmsg($lits);

    }


    /**
     * 提交站点提现
     */
    public function setwebcash()
    {
        $this->load->model('Jd_web_month_model');
        $row = $this->input->post();


        $id = $row['id'];
        $res = $this->db->select("id,status,webid")->from('jd_web_month')->where("`id`='$id'")->get()->result_array();
        $res = $res[0];

        if ($res['webid'] != $this->web_id) {
            $msg['msg'] = "站点错误";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }

        if ($res && $res['status'] == 0) {
            $row['status'] = 1;
            unset($row['id']);
            $res = $this->Jd_web_month_model->update("", 'id', $id, $row);
            // echo $this->db->last_query(); exit;
        } else {
            $msg['msg'] = "该月已经申请体现";
            $msg['code'] = 1;
            $this->sendjsonmsg($msg);
        }
        if ($res) {
            $msg['msg'] = "提交申请成功";
            $msg['code'] = 0;
        } else {
            $msg['msg'] = "提交申请失败";
            $msg['code'] = 1;
        }


        $this->sendjsonmsg($msg);
    }

    public function geshoplist()
    {
        $this->load->model('Jd_web_month_model');
        $page = $this->input->post('page');
        $epage = $this->input->post('epage');
        $where = "  where 1=1   ";
        $where .= $this->getsqlstrbyrow(['webid', 'name', 'user_id','phone',]);
        $where .= $this->getsqlstrbyrow(['username'], "p2");

        $where .= $this->gettimesqlstr();
        $where .= $this->gettimesqlstr('p1.update', 'update1', 'update2');

        if ($this->web_id == 1) {
            $_POST['webid'] = "全部";//搜全部站点
        }

        $_select = " p1.*,p2.username";
        $_order = " order by p1.id  desc ";
        $sql = "select SELECT from `jd_shop` as p1 
        left join jd_users as p2 on p1.user_id=p2.id    
				 SQL ORDER LIMIT";
        $_data = array("sql" => $sql,
            "_sql" => $where,
            "_select" => $_select,
            "_order" => $_order,
            "limit" => "",
            "page" => $page,
            "epage" => $epage);
        $result = $this->Jd_web_month_model->get_server_list($_data);


        foreach ($result['list'] as $id => $v) {
            switch ($v['status']) {
                case 0:
                    $result['list'][$id]['status'] = '待审核';
                    break;
                case 1:
                    $result['list'][$id]['status'] = '已通过';
                    break;
                case 2:
                    $result['list'][$id]['status'] = '已拒绝';
                    break;
                case 3:
                    $result['list'][$id]['status'] = '已发奖励';
                    break;
            }
            $result['list'][$id]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
            $result['list'][$id]['update'] =$v['update']?date('Y-m-d H:i:s', $v['update']):"";
        }

        $this->sendjsonmsg($result);

    }

    public function addshop()
    {
        $this->load->model('Jd_users_model');
        $row = $this->input->post();

        $name = $row['name'];

        $r = $this->Jd_users_model->checkshop($name);
        if ($r) {
            $msg['code'] = 1;
            $msg['msg'] = "该店铺已经存在";
            $this->sendjsonmsg($msg);
        }

        $r = $this->Jd_users_model->addshop($row);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "添加失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    public function editshop()
    {
        $this->load->model('Jd_users_model');
        $row = $this->input->post();
        $name = $row['name'];
        $r = $this->Jd_users_model->checkshop($name);
        if ($r) {
            $msg['code'] = 1;
            $msg['msg'] = "该店铺已经存在";
            $this->sendjsonmsg($msg);
        }

        $id = $row['id'];
        unset($row['id']);
        $r = $this->Jd_users_model->update('jd_shop', 'id', $id, $row);
        if (!$r) {
            $msg['code'] = 1;
            $msg['msg'] = "添加失败";
            $this->sendjsonmsg($msg);
        }
        $this->sendjsonmsg();
    }

    /**
     * 审核商户的充值
     * @param $id
     */
    public function shopExamine()
    {
        $id = $this->input->post('id');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "管理员可操作";
            $this->sendjsonmsg($msg);
        }

        $info = $this->Jd_users_model->getshopbydid($id);
        $this->load->model('Jd_users_model');
        $a = $this->Jd_users_model->approveshop($id);
        if ($a) {
            $nub = $this->Jd_users_model->getshopnub($info['user_id']);
            if ($nub['num'] == 1) {
                $row['user_id'] = $info['user_id'];
                $row['gold'] = 50;
                $row['remarks'] = '信息认证奖励';
                //  $result = $this->moneyupdate($row, 6, $id);
            }
            $msg['code'] = 0;
            $msg['msg'] = "审核成功";
            $this->sendjsonmsg($msg);
        }
        if (!$a) {
            $msg['code'] = 2;
            $msg['msg'] = "审核失败";
            $this->sendjsonmsg($msg);
        }
    }

    public function shoppay()
    {
        $id = $this->input->post('id');
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "管理员可操作";
            $this->sendjsonmsg($msg);
        }

        $info = $this->Jd_users_model->getshopbydid($id);
        $this->load->model('Jd_users_model');

        if ($info['status'] == 1) {
            $nub = $this->Jd_users_model->getshopnub($info['user_id']);
            if ($nub['num'] == 0) {
                $row['user_id'] = $info['user_id'];
                $row['gold'] = 50;
                $row['remarks'] = '信息认证奖励';
                $result = $this->moneyupdate($row, 6, $id);

                $a = $this->Jd_users_model->shopRefuse($id, '已经奖励', 3);


            } else {
                $msg['code'] = 1;
                $msg['msg'] = "该用户以发送奖励";
                $this->sendjsonmsg($msg);
            }
            $msg['code'] = 0;
            $msg['msg'] = "审核成功";
            $this->sendjsonmsg($msg);
        } else {
            $msg['code'] = 2;
            $msg['msg'] = "状态错误";
            $this->sendjsonmsg($msg);
        }

    }

    /**
     * 拒绝充值
     */
    public function shopRefuse()
    {
        $id = $this->input->post('id');
        $remarks = $this->input->post('remarks');
        $this->project = 3;
        if ($this->group != 4 && $this->group != 1) {
            $msg['code'] = 1;
            $msg['msg'] = "管理员可操作";
            $this->sendjsonmsg($msg);
        }
        $this->load->model('Jd_users_model');
        $a = $this->Jd_users_model->shopRefuse($id, $remarks, 2);
        if (!$a) {
            $msg['code'] = 2;
            $msg['msg'] = "状态更新失败";
            $this->sendjsonmsg($msg);
        }
        $msg['code'] = 0;
        $msg['msg'] = "拒绝完成";
        $this->sendjsonmsg($msg);
    }

}
